Useful AWS CLI Commands

AWS CLI commands that can help you manage your AWS resources effectively.

Bart Tworek1 min readawscliecrcodeartifact

Login to AWS ECR

To log in to AWS Elastic Container Registry (ECR), you can use the following command. This command retrieves an authentication token and uses it to authenticate Docker to your registry.

aws ecr get-login-password --region <your-region> | docker login --username AWS --password-stdin <your-account-id>.dkr.ecr.<your-region>.amazonaws.com

Replace <your-region> and <your-account-id> with your specific AWS region and account ID.

Login to AWS CodeArtifact

To log in to AWS CodeArtifact, you can use the following command. This command retrieves an authentication token and configures your package manager to use it.

aws codeartifact login --tool <your-package-manager> --repository <your-repo-name> --domain <your-domain-name> \
  --domain-owner <your-account-id> --region <your-region>

Replace <your-region>, <your-account-id>, <your-package-manager>, <your-repo-name>, and <your-domain-name> with your specific AWS region, account ID, package manager (e.g., npm, pip, twine, dotnet), repository name, and domain name respectively. For .NET projects, use --tool dotnet — this configures the NuGet source in your NuGet config.

Verify which identity the CLI is using

If a command fails with an unexpected permissions error, it's worth double-checking which account and role the CLI is actually authenticated as:

aws sts get-caller-identity

This returns the account ID, user/role ARN, and a unique identifier for the credentials currently in use, which is useful when you have multiple AWS profiles configured.

List ECR repositories

To see all container repositories in the current account and region:

aws ecr describe-repositories --region <your-region>