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
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
- 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
S3
bucket toEC2
instance or local machine
$ aws s3 cp s3://my_bucket/my_folder/my_file.ext my_copied_file.ex
- Copy an object from and
EC2
instance or local machine toS3
bucket
$ 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-stacks
andec2 describe-instances
to look at existing stacks or instances - Try to
--query
the output or display the--output
in different formats - Combine the
EC2
andS3
templates to create one template that launches both anEC2
instance and anS3
bucket - Validate the template using the
cloudformation validate-template
command - Update the
ImageId
to “ami-08f569078da6ad4c2” and run thecloudformation update-stack
command - Connect to the
EC2
instance using thepem
file - 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-stack
command