Bertug
Bertug

Reputation: 1090

Unable to Deploy with Correct AWS Profile Using SAM CLI - Profile Switching Issues

I'm trying to deploy a Lambda application to different environments (test and prod) using AWS SAM CLI. However, I'm running into issues where the deployment is not using the correct AWS account/profile. Below are the details of the problem and the solutions I've attempted so far.

Problem: When I run sam deploy --config-env prod --profile tale-garden-prod, it consistently deploys to the wrong AWS account. Additionally, when I run aws sts get-caller-identity --profile tale-garden-prod, it returns an incorrect account ID.

Solutions I've Tried: Reconfiguring AWS CLI Profile:

I used aws configure --profile tale-garden-prod to re-enter the correct IAM user credentials (Access Key and Secret Access Key). I checked the ~/.aws/credentials and ~/.aws/config files to ensure the correct details are present. Verifying Authentication:

I ran aws sts get-caller-identity --profile tale-garden-prod to verify which AWS account I was connected to using the specified profile. Setting Profile via Environment Variables:

I set the profile using the command export AWS_PROFILE=tale-garden-prod and then tried deploying again:

export AWS_PROFILE=tale-garden-prod
sam deploy --config-env prod

This did not resolve the issue either. Checking for MFA:

MFA (Multi-Factor Authentication) is not enabled on my account, so I ruled out this potential issue. SAM Build and Deploy:

I used sam build --profile tale-garden-prod to specify the correct profile during the build process, and then proceeded with the deployment. However, it still did not connect to the correct AWS account.

Upvotes: 0

Views: 129

Answers (1)

Bertug
Bertug

Reputation: 1090

Redefining config and credentials solved

Upvotes: 0

Related Questions