AWS/Quick Reference

From r00tedvw.com wiki
Jump to: navigation, search

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 
Personal tools
Namespaces

Variants
Actions
Navigation
Mediawiki
Confluence
DevOps Tools
Ubuntu
Oracle Linux
AWS
Windows
OpenVPN
Grafana
Pivotal
osTicket
OTRS
phpBB
WordPress
VmWare ESXI 5.1
Crypto currencies
HTML
CSS
Python
Java Script
PHP
Raspberry Pi
Canvas LMS
Kaltura Media Server
MetaSploit
Zoneminder
Photoshop CS2
Fortinet
Uploaded
Certifications
General Info
Games
Meal Plans
NC Statutes
Toolbox