AWS/Quick Reference
From r00tedvw.com wiki
(Difference between revisions)
Line 24: | Line 24: | ||
|} | |} | ||
<nowiki>~$ ssh -i ~/.ssh/grafana01.pem [email protected]</nowiki> | <nowiki>~$ ssh -i ~/.ssh/grafana01.pem [email protected]</nowiki> | ||
+ | |||
+ | |||
+ | =Cloud Formation= | ||
+ | create an S3 bucket with a lifecycle policy. export the name to be used outside of Cloud Formation. | ||
+ | <nowiki>{ | ||
+ | "AWSTemplateFormatVersion": "2010-09-09", | ||
+ | "Resources": { | ||
+ | "S3Bucket": { | ||
+ | "Type": "AWS::S3::Bucket", | ||
+ | "Properties": { | ||
+ | "LifecycleConfiguration": { | ||
+ | "Rules": [ | ||
+ | { | ||
+ | "Status": "Enabled", | ||
+ | "ExpirationInDays": "7" | ||
+ | } | ||
+ | ] | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | }, | ||
+ | "Outputs": { | ||
+ | "S3BucketName": { | ||
+ | "Value": { | ||
+ | "Ref": "S3Bucket" | ||
+ | }, | ||
+ | "Export": { | ||
+ | "Name": {"Fn::Sub": "${AWS::StackName}-S3BucketName"} | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } </nowiki> | ||
+ | |||
+ | =CodeBuild= | ||
+ | Deploy Cloud formation template and then copy directory recursively to S3 bucket. | ||
+ | <nowiki>version: 0.2 | ||
+ | |||
+ | phases: | ||
+ | install: | ||
+ | runtime-versions: | ||
+ | python: 3.7 | ||
+ | commands: | ||
+ | - echo $HOSTNAME | ||
+ | - uname -a | ||
+ | - gitdir=$(pwd) | ||
+ | - branch=$(basename $CODEBUILD_SOURCE_VERSION) | ||
+ | - stackname="a$CODEBUILD_PROJECT_UUID" | ||
+ | - printenv | ||
+ | - aws cloudformation deploy --template-file $gitdir/test.json --stack-name $stackname | ||
+ | - s3bucketname=$(aws cloudformation describe-stacks --stack-name $stackname | jq '.Stacks[0].Outputs[0].OutputValue' | sed s'/"//g') | ||
+ | - aws s3 mv $gitdir s3://$s3bucketname/$branch/ --recursive </nowiki> |
Revision as of 09:32, 14 October 2019
Quick Reference | AWS CLI
Logging in to EC2 instance
When creating the EC2 instance, you should be given a SSH key (.pem), you will use this to log into the instance. Most likely, you will need to change the file permissions of the SSH key. I also like to move it to a common location.
~$ mv /home/r00t/downloads/grafana01.pem /home/r00t/.ssh/ ~$ chmod 600 /home/r00t/.ssh/grafana01.pem
The Username will depend on the type of AMI image used:
AMI Type | Username |
---|---|
Amazon Linux 2 (AMI) | ec2-user
|
Centos AMI | centos
|
Debian AMI | admin or root
|
Fedora AMI | ec2-user or fedora
|
RHEL AMI | ec2-user or root
|
Suse AMI | ec2-user or root
|
Ubuntu AMI | ubuntu
|
~$ ssh -i ~/.ssh/grafana01.pem [email protected]
Cloud Formation
create an S3 bucket with a lifecycle policy. export the name to be used outside of Cloud Formation.
{ "AWSTemplateFormatVersion": "2010-09-09", "Resources": { "S3Bucket": { "Type": "AWS::S3::Bucket", "Properties": { "LifecycleConfiguration": { "Rules": [ { "Status": "Enabled", "ExpirationInDays": "7" } ] } } } }, "Outputs": { "S3BucketName": { "Value": { "Ref": "S3Bucket" }, "Export": { "Name": {"Fn::Sub": "${AWS::StackName}-S3BucketName"} } } } }
CodeBuild
Deploy Cloud formation template and then copy directory recursively to S3 bucket.
version: 0.2 phases: install: runtime-versions: python: 3.7 commands: - echo $HOSTNAME - uname -a - gitdir=$(pwd) - branch=$(basename $CODEBUILD_SOURCE_VERSION) - stackname="a$CODEBUILD_PROJECT_UUID" - printenv - aws cloudformation deploy --template-file $gitdir/test.json --stack-name $stackname - s3bucketname=$(aws cloudformation describe-stacks --stack-name $stackname | jq '.Stacks[0].Outputs[0].OutputValue' | sed s'/"//g') - aws s3 mv $gitdir s3://$s3bucketname/$branch/ --recursive