Cheat sheet¶
CloudFormation¶
- Deploying your stack using the AWS CLI via
CloudFormation
$ aws --profile <profile> cloudformation create-stack --stack-name <stack> [--template-body <template>] [--parameters <parameters>]
Note
Local files need to be prefixed with file://
- Verify and check stack deployment using the AWS CLI
$ aws --profile <profile> cloudformation describe-stacks [--stack-name <stack>]
- List resources of a stack using the AWS CLI
$ aws --profile <profile> cloudformation list-stack-resources --stack-name <stack>
- Validate your CloudFormation template using the AWS CLI
$ aws --profile <profile> cloudformation validate-template --template-body <template>
- Update your stack using the AWS CLI
$ aws --profile <profile> cloudformation update-stack --stack-name <stack> [--template-body <template>] [--parameters <parameters>]
EC2 Instance¶
- Connecting to the deployed
EC2instance via ssh
$ ssh -i <key.pem> user@<publicip>
To obtain the PublicIpAddress of your instance:
$ aws ec2 describe-instances --instance-ids i-0787e4282810ef9cf --query 'Reservations[0].Instances[0].PublicIpAddress'
Note
The “key.pem” must only allow read access to the user
- Key - The key specified must be at the path indicated. It must be the private key. Permissions on the key must be restricted to the owner and the key must be associated with the instance.
- User - The user name must match the default user name associated with the AMI you used to launch the instance. For an Ubuntu AMI, this is
ubuntu. For an Amazon Linux AMI, it isec2-user. - Instance - The public IP address or DNS name of the instance. Verify that the address is public and that port 22 is open to your local machine on the instance’s security group.
S3 bucket¶
- Copy an object from an
S3bucket toEC2instance or local machine
$ aws s3 cp s3://my_bucket/my_folder/my_file.ext my_copied_file.ex
- Copy an object from and
EC2instance or local machine toS3bucket
$ aws s3 cp my_copied_file.ext s3://my_bucket/my_folder/my_file.ext
- Download an entire Amazon S3 bucket to a local directory on your instance
$ aws s3 sync s3://remote_S3_bucket local_directory
Exercise¶
- Configure your AWS CLI
- Run the
cloudformation describe-stacksandec2 describe-instancesto look at existing stacks or instances - Try to
--querythe output or display the--outputin different formats - Combine the
EC2andS3templates to create one template that launches both anEC2instance and anS3bucket - Validate the template using the
cloudformation validate-templatecommand - Update the
ImageIdto “ami-08f569078da6ad4c2” and run thecloudformation update-stackcommand - Connect to the
EC2instance using thepemfile - Copy the contents of this S3 bucket (s3://buaws-training-shared/test_reads.fastq.gz) to the instance
- Delete the stack using the
cloudformation delete-stackcommand