CLI, CloudShell, CDK, SAM
Update the awscli regularly
[2022-Jun] aws-cli/2.7.9 Python/3.9.11 Windows/10 exe/AMD64 prompt/off
Explore further
AWS CloudShell - https://docs.aws.amazon.com/cloudshell/latest/userguide/welcome.html
AWS CLI
The AWS Command Line Interface (AWS CLI) enables you to interact with AWS services using commands in your command-line shell.
Setup
Prerequisite: install unzip;
Review Docs - AWS CLI
Install unzip
$ sudo apt install unzipInstall - AWS CLI
Source: AWS Installing or updating the latest version of the AWS CLI
//tbd
Update the awscli
$ curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" unzip awscliv2.zip
$ sudo ./aws/install --bin-dir /usr/local/bin --install-dir /usr/local/aws-cli --update
aws-cli/2.17.14 Python/3.11.9 Linux/5.15.153.1-microsoft-standard-WSL2 exe/x86_64.ubuntu.22
Configure - AWS CLI
Source: AWS CLI - Quick Setup - New configuration quick setup
For new & clean environment, configure the "default" config and profile
The configurations are stored in the ~/.aws folder for (macOS/Linux); or %USERPROFILE%.aws\ folder for (Windows), in two files: config and credentials
[Optional] Configure for a specific "profile", for example: "produser"
Docs - AWS CLI
How-to
after windows update aws error: bus error
Resolution: reinstall aws cli; see Setup
CloudShell
Source: AWS CloudShell
Command line access to AWS resources and tools directly from a browser.
There is no additional charge for AWS CloudShell.
Useful commands to explore:
zsh; vim ~/.zshrc
CDK
The AWS Cloud Development Kit (AWS CDK) is a software development framework for defining your cloud application resources using familiar programming languages including: Python, Typescript, etc. Regardless of the programming languages, CDK uses the same back end which runs on Node.js. Therefore, the development computer needs to have the Node.js prerequisite installed.
Source: Getting started with the AWS CDK
Step-by-Step Instructions
Prerequisite - Node.js & NPM; See SETUP > Dev Environment > Node.js
Prerequisite - AWS CLI; See Configure - AWS CLI; and review CDK credential requirements below
[Optional] Setup User Policy
Review Docs - CDK
CDK credentials requirements
Ensure the development computer has been configured with the "region" and "credentials" in the config and credentials files, respectively. Both files are stored in the ~/.aws folder. For more details, see Configure - AWS CLI.
NOTE: although the AWS CDK uses credentials from the same configuration files as the AWS CLI, it behaves differently. If you use a named profile from the credentials file, the config file must have a profile of the same name specifying the region. In addition, do not use a profile named containing the word "default" (e.g. [profile default]). [see Getting started with the AWS CDK]
Install - CDK
CDK Bootstrapping
Deploying stacks with the AWS CDK requires the AWS CloudFormation stack (called CDKToolkit) and a dedicated Amazon S3 buckets to be available during deployment. The process is called bootstrapping, and it's a onetime setup for the AWS Account. The S3 bucket and the CloudFormation "CDKToolkit" resources are reusable by any cdk projects.
During "CDK bootstrapping", the following five IAM Roles are also created:
CLEANUP
As mentioned above, the resources created by bootstrapping are reusable across cdk projects so they should not be deleted. However, to completely cleanup all the resources created during CDK bootstrapping:
Delete the S3 bucket
Delete the CloudFormation "CDKToolkit"
Delete the five IAM roles; go to IAM console, and search for "cdk-"
[Optional] Setup User Policy
Define user policy needed to deploy AWS S3.
If the user belongs to the Administrator group; then the following policy will not be needed.
Tutorials
Python - Python Tutorial
Python - Youtube - Getting Started with AWS CDK and Python | Step by Step Tutorial
Docs - CDK
API - Python - PyPi.org - aws-cdk.aws-s3
API - Typescript - tbd
AWS Cloud Development Kit (CDK) v2 - Developer Guides
Troubleshooting
cdk deploy error: fail: No bucket named; Is account <acct#> bootstrapped?
One of the two resources created by the cdk bootstrap: the S3 bucket or the CloudFormation stack called "CDKToolkit" was not delete. Note: if you only delete the S3 bucket, the next cdk deploy will fail indicating that the account has not been "bootstrap" but attempt to cdk bootstrap will look like success with "no change" shown on the output, but the S3 bucket is not created and the cdk deploy will still fail, as shown below. The reason is because cdk bootstrap still detects the CloudFormation resource, i.e., "CDKToolkit".
AWS CLI SAM
Source: AWS Serverless Application Model - Installing the AWS SAM CLI
Prerequisite: AWS CLI version 2
Download the AWS SAM CLI .zip file to a directory
Verify the integrity and authenticity of the downloaded installer files by generating a hash value using the following command:
Unzip the installation files into the
sam-installation/subdirectory
Install the AWS SAM CLI
References
[REF-1] AWS Configuration and credential file settings
[REF-2] AWS Environment variables to configure the AWS CLI
Last updated