Cheat sheet

AWS CLI

  1. Configuring your AWS CLI
$ aws configure --profile <profile>

CloudFormation

  1. 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://

  1. Verify and check stack deployment using the AWS CLI
$ aws --profile <profile> cloudformation describe-stacks [--stack-name <stack>]
  1. List resources of a stack using the AWS CLI
$ aws --profile <profile> cloudformation list-stack-resources --stack-name <stack>
  1. Validate your CloudFormation template using the AWS CLI
$ aws --profile <profile> cloudformation validate-template --template-body <template>
  1. Update your stack using the AWS CLI
$ aws --profile <profile> cloudformation update-stack --stack-name <stack> [--template-body <template>] [--parameters <parameters>]

EC2 Instance

  1. Connecting to the deployed EC2 instance 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

  1. 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.
  2. 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 is ec2-user.
  3. 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

  1. Copy an object from an S3 bucket to EC2 instance or local machine
$ aws s3 cp s3://my_bucket/my_folder/my_file.ext my_copied_file.ex
  1. Copy an object from and EC2 instance or local machine to S3 bucket
$ aws s3 cp my_copied_file.ext s3://my_bucket/my_folder/my_file.ext
  1. Download an entire Amazon S3 bucket to a local directory on your instance
$ aws s3 sync s3://remote_S3_bucket local_directory

Exercise

  1. Configure your AWS CLI
  2. Run the cloudformation describe-stacks and ec2 describe-instances to look at existing stacks or instances
  3. Try to --query the output or display the --output in different formats
  4. Combine the EC2 and S3 templates to create one template that launches both an EC2 instance and an S3 bucket
  5. Validate the template using the cloudformation validate-template command
  6. Update the ImageId to “ami-08f569078da6ad4c2” and run the cloudformation update-stack command
  7. Connect to the EC2 instance using the pem file
  8. Copy the contents of this S3 bucket (s3://buaws-training-shared/test_reads.fastq.gz) to the instance
  9. Delete the stack using the cloudformation delete-stack command