Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joerncodes/6d96114dbbd84f3acd70a2ddb9f056b1 to your computer and use it in GitHub Desktop.
Save joerncodes/6d96114dbbd84f3acd70a2ddb9f056b1 to your computer and use it in GitHub Desktop.
Creating an AWS Profile to Work With CDK

Creating an AWS Profile to Work With CDK

Author: Jörn Meyer
Last change: 2023-02-02

Install CLI tools

In order to use AWS CDK to build AWS stacks, you need to install the aws and cdk command line tools first:

  1. Follow the AWS CLI install instructions for your operating system.
  2. Run npm install -g aws-cdk

Create AWS Profile

In your home folder, there should be a folder called .aws (ls ~/.aws if you're unsure). Create it if it doesn't exist. Find or create two files:

  1. config stores the profile names and configuration pertaining to them
  2. credentials stores your API credentials

Make a new section in config:

[your-profile-name]
region=eu-central-1

Create Credentials

  1. Log into the AWS console.
  2. Click on your username in top right corner.
  3. Choose Security credentials from the dropdown.
  4. Find the section called Access keys and click the button labelled Create access key
  5. Select Command line interface from the radio button menu. Check the checkbox labelled I understand the above recommendation and want to proceed to create an access key.

  1. Provide your new credentials with a fitting name, like cli-access and click Create access key
  2. The next menu shows you the Access key and the Secret access key. Write them both down in your password manager of choice, as you can never access them again after you close the menu.

Configuring Credentials

Edit ˜/.aws/credentials and add:

[your-profile-name]
aws_access_key_id=ACCESS_KEY_YOU_JUST_CREATED
aws_secret_access_key=SAME_BUT_FOR_SECRET

Selecting / Switching profiles

After these steps are complete, you can execute the command export AWS_PROFILE=your-profile-name to select your profile. You will have to do this every time you open a new terminal / shell. If you want to avoid that, you can also give your profile the name default, but I would discourage that, since the export route makes you consciously choose the correct profile before you perform any potentially destructive actions.

That's it! Both aws and cdk are now working with your selected profile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment