AWS ‐ CLI - FullstackCodingGuy/Developer-Fundamentals GitHub Wiki
Installing in windows
Run this in command prompt : msiexec.exe /i https://awscli.amazonaws.com/AWSCLIV2.msi
To configure the profile
Aws configure --profile <profilename>
To get help of service
aws dynamodb help
aws ec2 help
To set default region
aws configure set region us-east-1
To get the EC2 instances
Aws ec2 describe-instances --profile <profilename> --region ca-central-1
To get the users
aws iam list-users --profile <profilename>
To get the dynamodb tables
aws dynamodb list-tables --profile clip1 --region us-east-1
aws ecs create-cluster --cluster-name --region us-east-1
Configuring Ingress for the ECS container - configuring port 80 to be exposed, by enabling in security group aws ec2 authorize-security-group-ingress --group-id --protocol tcp --port 80 --cidr 0.0.0.0/0
aws ecs register-task-definition --cli-input-json file://filename.json
aws ecs create-service --cluster <clster-name> --service-name <name-given-in-above-json> --task-definition <task-def-name>:<version> --desired-count 1 --launch-type "FARGATE" --network-configuration "awsvpcConfiguration={subnets=[],securityGroups=[],assignPublicIp=ENABLED}"
aws ecs list-services --cluster <cluster=name>
aws ecs describe-services --cluster <cluster=name>
To list Amazon Elastic Container Registry (ECR) repositories using AWS CLI, use the following command:
aws ecr describe-repositories --region <region-name>
aws ecr describe-repositories --region us-east-1
This will return a JSON output containing all ECR repositories in us-east-1.
If you only want to see repository names:
aws ecr describe-repositories --query 'repositories[*].repositoryName' --output table
or in a simple list format:
aws ecr describe-repositories --query 'repositories[*].repositoryName' --output text
If you want to see the images inside a repository:
aws ecr list-images --repository-name <your-repository-name> --region <region-name>
Example:
aws ecr list-images --repository-name my-next-app --region us-east-1
To find a specific repository:
aws ecr describe-repositories --query "repositories[?repositoryName=='my-next-app']"
To push a local Docker image to AWS Elastic Container Registry (ECR), follow these steps:
First, authenticate Docker to AWS ECR using the AWS CLI:
aws ecr get-login-password --region <region-name> | docker login --username AWS --password-stdin <aws_account_id>.dkr.ecr.<region-name>.amazonaws.com
🔹 Example for us-east-1
:
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 123456789012.dkr.ecr.us-east-1.amazonaws.com
If you haven't created a repository yet, create one:
aws ecr create-repository --repository-name my-next-app --region <region-name>
🔹 Example:
aws ecr create-repository --repository-name my-next-app --region us-east-1
Tag your local image to match the ECR repository URL:
docker tag <local-image-name>:<tag> <aws_account_id>.dkr.ecr.<region-name>.amazonaws.com/<repository-name>:<tag>
🔹 Example:
docker tag my-next-app:latest 123456789012.dkr.ecr.us-east-1.amazonaws.com/my-next-app:latest
Now, push the image to ECR:
docker push <aws_account_id>.dkr.ecr.<region-name>.amazonaws.com/<repository-name>:<tag>
🔹 Example:
docker push 123456789012.dkr.ecr.us-east-1.amazonaws.com/my-next-app:latest
After pushing the image, verify it using:
aws ecr list-images --repository-name my-next-app --region us-east-1
Now, you can use the image in AWS ECS (Fargate), Kubernetes (EKS), or Lambda (Container Image).
Would you like help deploying it on ECS or Lambda? 🚀
aws s3 mb s3://your-bucket-name
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicRead",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::<bucket-name>/*"
}
]
}
aws ec2 describe-images --owners amazon --filters "Name=name,Values=amzn2-ami-hvm-*-x86_64-gp2" --region <region> --query "Images[*].[ImageId, Name]" --output table
This will return a list of Amazon Linux 2 AMIs that are available.
read
The simplest way to delete all AWS resources is to delete the AWS CloudFormation stack if you used AWS SAM or CloudFormation. However, if resources were manually created, the best approach is to delete everything under your AWS account using AWS Nuke.
1. Delete All Resources Using AWS Nuke (Recommended)
AWS Nuke is a third-party tool designed to delete all AWS resources in an account.
wget https://github.com/rebuy-de/aws-nuke/releases/latest/download/aws-nuke-linux-amd64 -O aws-nuke
chmod +x aws-nuke
sudo mv aws-nuke /usr/local/bin/
Create a configuration file (nuke-config.yml
):
regions:
- "us-east-1"
- "us-west-2"
account-blocklist:
- "123456789012" # (Prevent accidental deletion of important accounts)
accounts:
"your-account-id":
filters:
IAMUser:
- "admin"
IAMRole:
- "OrganizationAccountAccessRole"
aws-nuke -c nuke-config.yml --force
- This will list all resources before deleting them.
- Type "Nuke it" to confirm.
If you want to delete the entire AWS account (not just resources):
- Go to AWS Console → Billing Dashboard
- Click Close Account
- For cleaning up all resources: ✅ Use AWS Nuke
- For deleting AWS deployments only: ✅ Use CloudFormation delete-stack
- For permanently closing AWS account: ✅ Delete via AWS Console
Run this command to create a secret:
# to create secret
aws secretsmanager create-secret \
--name DocumentDBSecret \
--secret-string '{"username": "admin", "password": "SecurePass123"}'
# to update secret
aws secretsmanager update-secret \
--secret-id DocumentDBSecret \
--secret-string '{"username": "admin", "password": "New#SecurePass123"}'
# to retrieve secret
aws secretsmanager get-secret-value --secret-id DocumentDBSecret