AWS
Elastic Beanstalk CLI
Change Account
Cloud Computing
DevOps

How to change the AWS account using the Elastic Beanstalk CLI

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

The Elastic Beanstalk CLI does not have a magical "switch account" state of its own. It uses AWS credentials and profiles the same way other AWS tools do. So changing the AWS account for eb usually means changing which AWS profile or credentials the command resolves to, then reinitializing or updating the project if the application and region mapping also change.

How The EB CLI Chooses Credentials

The EB CLI relies on the normal AWS credential chain. In practice, the most common sources are:

  • the AWS_PROFILE environment variable
  • the default profile in ~/.aws/credentials and ~/.aws/config
  • explicit --profile usage when supported by the command
  • temporary environment variables such as AWS_ACCESS_KEY_ID

That means the cleanest account-switching workflow is to define separate named AWS profiles and run eb with the profile for the target account.

Step 1: Create Separate AWS Profiles

Configure one profile per account.

bash
aws configure --profile personal
aws configure --profile work

That writes separate entries in the AWS shared config and credentials files. Once those exist, you can confirm them with:

bash
aws configure list-profiles

This is much safer than editing access keys in place every time you want to switch.

Step 2: Run EB With The Target Profile

A common approach is to export AWS_PROFILE before running Elastic Beanstalk commands.

bash
export AWS_PROFILE=work
eb status
eb deploy

On Windows PowerShell:

powershell
$Env:AWS_PROFILE = "work"
eb status

This changes the account context for that shell session.

If you only want one command to use a different account, prefix the command inline on Unix-like shells:

bash
AWS_PROFILE=personal eb list

That avoids permanently changing the shell environment.

Step 3: Reinitialize If The Project Points At The Wrong App

Credentials alone are not the whole story. The local Elastic Beanstalk project also stores configuration in .elasticbeanstalk/config.yml, including the application and environment association.

If you switch to another AWS account and the local project is still tied to an application that exists only in the old account, commands may fail or point to the wrong resources.

In that case, re-run initialization with the new profile:

bash
AWS_PROFILE=work eb init

During eb init, choose the correct region, application, and platform for the target account.

That is the step many people miss. They switch credentials but forget the local project metadata is still tied to the previous account's app.

Verifying Which Account You Are Using

Before deploying anything, check the active AWS identity directly.

bash
AWS_PROFILE=work aws sts get-caller-identity

This is the fastest sanity check. If the returned account ID is wrong, stop there and fix the profile selection before you run eb deploy.

Temporary Credentials And SSO

If your organization uses AWS SSO or temporary credentials, the same principle still applies: the EB CLI must resolve credentials for the correct account. In those setups, the account switch often happens by authenticating the desired AWS CLI profile first, then running eb under that profile.

The workflow changes slightly, but the credential-resolution model does not.

A Safe Team Workflow

A practical team pattern is:

  • keep one named profile per account
  • verify identity with aws sts get-caller-identity
  • run eb init when moving a project to a different account or region
  • avoid relying on whichever account happens to be configured as default

That reduces accidental deployments to the wrong account.

Common Pitfalls

  • Editing the default AWS profile repeatedly instead of using named profiles.
  • Switching credentials but forgetting the local .elasticbeanstalk/config.yml still targets the old app or region.
  • Running eb deploy before checking aws sts get-caller-identity.
  • Mixing shell sessions and forgetting which one has AWS_PROFILE set.
  • Assuming the EB CLI stores a separate persistent account switch independent of AWS profiles.

Summary

  • Changing the AWS account for the Elastic Beanstalk CLI usually means changing the AWS profile or credential source.
  • Use named AWS profiles instead of rewriting default credentials repeatedly.
  • Run eb under the target profile through AWS_PROFILE or equivalent shell configuration.
  • Re-run eb init if the project needs to point at a different application or region in the new account.
  • Verify the active account with aws sts get-caller-identity before deploying.

Course illustration
Course illustration

All Rights Reserved.