2

I'm having an issue while logging into ECR.

buildspec.yml

...
- echo $AWS_DEFAULT_REGION and $AWS_ACCOUNT_ID
- aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com

Following command return me "us-east-2" and "" ($AWS_ACCOUNT_ID is empty)

- echo $AWS_DEFAULT_REGION and $AWS_ACCOUNT_ID

so that's why I'm unable to login to ECR.

0

2 Answers 2

3

Because there is no default codebuild environment variable named AWS_ACCOUNT_ID

Here Environment variables in build environments you can find all default codebuild environment variables.

Sign up to request clarification or add additional context in comments.

3 Comments

Is there any work around to get the account ID?
@Yougesh you can instrument something with GetCallerIdentity API call.
thanks for instruction, I have resolved by $ aws sts get-caller-identity --query "Account" --output text
3

In addition to @samtoddler, you can add this to your CloudFormation template, this will give you the output for $AWS_ACCOUNT_ID in the buildspec.yml

"EnvironmentVariables": [
                        {
                            "Name": "AWS_ACCOUNT_ID",
                            "Value": {
                                "Ref": "AWS::AccountId"
                            }
                        }
                    ],

1 Comment

perfect! or with cdk: environment_variables={"AWS_ACCOUNT_ID": aws_codebuild.BuildEnvironmentVariable( value=os.getenv('CDK_DEFAULT_ACCOUNT') or '')}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.