Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin...

101
©2015, Amazon Web Services, Inc. or its affiliates. All rights reserved Deep Dive: AWS Command Line Interface Martin Elwin

Transcript of Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin...

Page 1: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

©2015,  Amazon  Web  Services,  Inc.  or  its  affiliates.  All  rights  reserved

Deep Dive: AWS Command Line Interface

Martin Elwin

Page 2: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

CRASH COURSE

Intro to the AWS CLI

FOUNDATION ADVANCED SCENARIOS

Exploring Key Functionality

Looking at Advanced CLI Features

Page 3: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

Crash Course Intro to the AWS CLI

Page 4: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

AWS Command Line Interface Unified tool to manage your AWS services

Page 5: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

MSI (Windows)

Bundled (cross platform)

pip (cross platform)

Page 6: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

aws  configure  

Page 7: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

$  aws  ec2  describe-­‐instances  

Service (command) Operation (subcommand)

Page 8: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

$  aws  iam  list-­‐access-­‐keys  

Service (command) Operation (subcommand)

Page 9: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

{        "Places":  [                  {                            "City":  "Seattle",                    "State":  "WA"          },          {              "City":  "Las  Vegas",            "State":  "NV"          }        ]    

}      

--output JSON

Page 10: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

PLACES    Seattle      WA  PLACES    Las  Vegas  NV  

--output text

Page 11: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐    |      SomeOperationName        |    +-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+    ||                  Places              ||    |+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+|    ||  City              |  State      ||    |+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+|    ||  Seattle        |  WA            ||    ||  Las  Vegas    |  NV            ||    |+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+|    

--output table

Page 12: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

All Outputs

JSON Text

PLACES    Seattle        WA  PLACES    Las  Vegas    NV  

Table

-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐    |        SomeOperationName      |    +-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+    ||                  Places              ||    |+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+|    ||  City              |  State      ||    |+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+|    ||  Seattle        |  WA            ||    ||  Las  Vegas    |  NV            ||    |+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+|    

{        "Places":  [                  {                            "City":  "Seattle",              

     "State":  "WA"      },      {        "City":  ”Las  Vegas",      "State":  "NV"      }    

     ]    }      

Page 13: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

Demo

Basic AWS CLI Usage

Page 14: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

Foundation Exploring Key Functionality

Page 15: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

Configuration

Page 16: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

aws  configure    

Page 17: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

aws  configure    

AWS  Access  Key  ID  [**ABCD]:    AWS  Secret  Access  Key  [****************EFGH]:    Default  region  name  [us-­‐west-­‐2]:    Default  output  format  [None]:      

Page 18: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

aws  configure  <subcommand>    

Page 19: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

list - list common configuration sources get  -­‐  get  the  value  of  a  single  config  var  set  -­‐  set  the  value  of  a  single  config  var  

aws  configure  <subcommand>    

Page 20: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

aws  configure  get  region    

Page 21: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

aws  configure  set  region  eu-­‐west-­‐1

Page 22: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

A profile is a group of configuration values

Page 23: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

aws  configure  -­‐-­‐profile  prod

Page 24: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

aws  configure  set  profile.prod.region  eu-­‐west-­‐1

Page 25: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

Configuration Files

~/.aws/credentials   ~/.aws/config

•  Supported by all AWS SDKs •  Only contains credentials

•  Used only by the CLI •  Can contain credentials (but not the default behavior)

Page 26: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

~/.aws/credentials ~/.aws/config

Page 27: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

aws configure set profile.prod.aws_access_key_id foo

~/.aws/credentials ~/.aws/config

Page 28: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

aws configure set profile.prod.aws_access_key_id foo

~/.aws/credentials ~/.aws/config [prod] aws_access_key_id = foo

Page 29: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

aws configure set profile.prod.aws_secret_access_key bar

~/.aws/credentials ~/.aws/config [prod] aws_access_key_id = foo

Page 30: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

aws configure set profile.prod.aws_secret_access_key bar

~/.aws/credentials ~/.aws/config [prod] aws_access_key_id = foo aws_secret_access_key = bar

Page 31: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

aws configure set profile.prod.region eu­west­1

~/.aws/credentials ~/.aws/config [prod] aws_access_key_id = foo aws_secret_access_key = bar

Page 32: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

aws configure set profile.prod.region eu­west­1

~/.aws/credentials ~/.aws/config [prod] aws_access_key_id = foo aws_secret_access_key = bar

[profile prod] region = eu-west-1

Page 33: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

aws configure set profile.prod.output text

~/.aws/credentials ~/.aws/config [prod] aws_access_key_id = foo aws_secret_access_key = bar

[profile prod] region = eu-west-1

Page 34: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

aws configure set profile.prod.output text

~/.aws/credentials ~/.aws/config [prod] aws_access_key_id = foo aws_secret_access_key = bar

[profile prod] region = eu-west-1 output = text

Page 35: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

create-new-user.sh

aws  iam  create-­‐user  -­‐-­‐user-­‐name  summit-­‐user    = aws  iam  create-­‐access-­‐key  -­‐-­‐user-­‐name  summit-­‐user  \  

 -­‐-­‐query   \      -­‐-­‐output  text

=  |  cut  -­‐d  -­‐f  1= |  cut  -­‐d  -­‐f  2

aws  configure    profile.summit.aws_access_key_id  aws  configure    profile.summit.secret_access_key  

Page 36: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

aws  iam  create-­‐user  -­‐-­‐user-­‐name  summit-­‐user    = aws  iam  create-­‐access-­‐key  -­‐-­‐user-­‐name  summit-­‐user  \  

 -­‐-­‐query   \      -­‐-­‐output  text

=  |  cut  -­‐d  -­‐f  1= |  cut  -­‐d  -­‐f  2

aws  configure    profile.summit.aws_access_key_id  aws  configure    profile.summit.secret_access_key  

create-new-user.sh

Page 37: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

aws  iam  create-­‐user  -­‐-­‐user-­‐name  summit-­‐user    = aws  iam  create-­‐access-­‐key  -­‐-­‐user-­‐name  summit-­‐user  \  

 -­‐-­‐query   \      -­‐-­‐output  text

=  |  cut  -­‐d  -­‐f  1= |  cut  -­‐d  -­‐f  2

aws  configure    profile.summit.aws_access_key_id  aws  configure    profile.summit.secret_access_key  

create-new-user.sh

Page 38: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

aws  iam  create-­‐user  -­‐-­‐user-­‐name  summit-­‐user    = aws  iam  create-­‐access-­‐key  -­‐-­‐user-­‐name  summit-­‐user  \  

 -­‐-­‐query   \      -­‐-­‐output  text

=  |  cut  -­‐d  -­‐f  1= |  cut  -­‐d  -­‐f  2

aws  configure    profile.summit.aws_access_key_id  aws  configure    profile.summit.secret_access_key  

create-new-user.sh

Page 39: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

aws  iam  create-­‐user  -­‐-­‐user-­‐name  summit-­‐user    = aws  iam  create-­‐access-­‐key  -­‐-­‐user-­‐name  summit-­‐user  \  

 -­‐-­‐query   \      -­‐-­‐output  text

=  |  cut  -­‐d  -­‐f  1= |  cut  -­‐d  -­‐f  2

aws  configure    profile.summit.aws_access_key_id  aws  configure    profile.summit.secret_access_key  

create-new-user.sh

Page 40: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

aws  iam  create-­‐user  -­‐-­‐user-­‐name  summit-­‐user    = aws  iam  create-­‐access-­‐key  -­‐-­‐user-­‐name  summit-­‐user  \  

 -­‐-­‐query   \      -­‐-­‐output  text

=  |  cut  -­‐d  -­‐f  1= |  cut  -­‐d  -­‐f  2

aws  configure    profile.summit.aws_access_key_id  aws  configure    profile.summit.secret_access_key  

create-new-user.sh

Page 41: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

Use the aws  configure   suite of subcommands

Page 42: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

Query

Page 43: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

-­‐-­‐query  (string)      A  JMESPath  query  to  use  in  filtering  the  response  data.  

Page 44: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

Implementation Details --query Processing

Page 45: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

Implementation Details --query Processing

Page 46: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

Implementation Details --query Processing

Page 47: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

Implementation Details --query Processing

Page 48: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

Implementation Details --query Processing

-­‐-­‐query  User[0].[UserName,Path,UserId]  

Page 49: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

Implementation Details --query Processing

-­‐-­‐query  User[0].[UserName,Path,UserId]  

Page 50: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

Implementation Details --query Processing

Page 51: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

Implementation Details --query Processing

Page 52: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

http://jmespath.org

A Query Language for JSON

Page 53: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

Demo

JMESPATH

Page 54: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

http://jmespath.org

A Query Language for JSON

Page 55: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

Waiters

Page 56: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

Amazon EC2 Instance State Transitions

Page 57: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

ec2-instance-running.sh

#!/bin/bash    instance_id=$(aws  ec2  run-­‐instances  -­‐-­‐image-­‐id  ami-­‐12345  \  

 -­‐-­‐query  Reservations[].Instances[].InstanceId  \    -­‐-­‐output  text)  

instance_state=$(aws  ec2  describe-­‐instances  -­‐-­‐instance-­‐ids  $instance_id  \    -­‐-­‐query  'Reservations[].Instances[].State.Name')  

while  [  "$instance_state"  !=  "running"  ]    do    

 sleep  1            instance_state=$(aws  ec2  describe-­‐instances  -­‐-­‐instance-­‐ids  $instance_id  \  

 -­‐-­‐query  'Reservations[].Instances[].State.Name')    done  

Page 58: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

#!/bin/bash    instance_id=$(aws  ec2  run-­‐instances  -­‐-­‐image-­‐id  ami-­‐12345  \  

 -­‐-­‐query  Reservations[].Instances[].InstanceId  \    -­‐-­‐output  text)  

instance_state=$(aws  ec2  describe-­‐instances  -­‐-­‐instance-­‐ids  $instance_id  \    -­‐-­‐query  'Reservations[].Instances[].State.Name')  

while  [  "$instance_state"  !=  "running"  ]    do    

 sleep  1            instance_state=$(aws  ec2  describe-­‐instances  -­‐-­‐instance-­‐ids  $instance_id  \  

 -­‐-­‐query  'Reservations[].Instances[].State.Name')    done  

ec2-instance-running.sh

Page 59: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

#!/bin/bash    instance_id=$(aws  ec2  run-­‐instances  -­‐-­‐image-­‐id  ami-­‐12345  \  

 -­‐-­‐query  Reservations[].Instances[].InstanceId  \    -­‐-­‐output  text)  

instance_state=$(aws  ec2  describe-­‐instances  -­‐-­‐instance-­‐ids  $instance_id  \    -­‐-­‐query  'Reservations[].Instances[].State.Name')  

while  [  "$instance_state"  !=  "running"  ]    do    

 sleep  1            instance_state=$(aws  ec2  describe-­‐instances  -­‐-­‐instance-­‐ids  $instance_id  \  

 -­‐-­‐query  'Reservations[].Instances[].State.Name')    done  

ec2-instance-running.sh

Page 60: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

#!/bin/bash    instance_id=$(aws  ec2  run-­‐instances  -­‐-­‐image-­‐id  ami-­‐12345  \  

 -­‐-­‐query  Reservations[].Instances[].InstanceId  \    -­‐-­‐output  text)  

instance_state=$(aws  ec2  describe-­‐instances  -­‐-­‐instance-­‐ids  $instance_id  \    -­‐-­‐query  'Reservations[].Instances[].State.Name')  

while  [  "$instance_state"  !=  "running"  ]    do    

 sleep  1            instance_state=$(aws  ec2  describe-­‐instances  -­‐-­‐instance-­‐ids  $instance_id  \  

 -­‐-­‐query  'Reservations[].Instances[].State.Name')    done  

ec2-instance-running.sh

Page 61: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

#!/bin/bash    instance_id=$(aws  ec2  run-­‐instances  -­‐-­‐image-­‐id  ami-­‐12345  \  

 -­‐-­‐query  Reservations[].Instances[].InstanceId  \    -­‐-­‐output  text)  

instance_state=$(aws  ec2  describe-­‐instances  -­‐-­‐instance-­‐ids  $instance_id  \    -­‐-­‐query  'Reservations[].Instances[].State.Name')  

while  [  "$instance_state"  !=  "running"  ]    do    

 sleep  1            instance_state=$(aws  ec2  describe-­‐instances  -­‐-­‐instance-­‐ids  $instance_id  \  

 -­‐-­‐query  'Reservations[].Instances[].State.Name')    done  

ec2-instance-running.sh

Page 62: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

#!/bin/bash    instance_id=$(aws  ec2  run-­‐instances  -­‐-­‐image-­‐id  ami-­‐12345  \  

 -­‐-­‐query  Reservations[].Instances[].InstanceId  \    -­‐-­‐output  text)  

instance_state=$(aws  ec2  describe-­‐instances  -­‐-­‐instance-­‐ids  $instance_id  \    -­‐-­‐query  'Reservations[].Instances[].State.Name')  

while  [  "$instance_state"  !=  "running"  ]    do    

 sleep  1            instance_state=$(aws  ec2  describe-­‐instances  -­‐-­‐instance-­‐ids  $instance_id  \  

 -­‐-­‐query  'Reservations[].Instances[].State.Name')    done  

ec2-instance-running.sh

• No timeouts

• Failure states

• Hand-written code

Page 63: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

ec2-waiters.sh

instance_id=$(aws  ec2  run-­‐instances  -­‐-­‐image-­‐id  ami-­‐12345  \    -­‐-­‐query  Reservations[].Instances[].InstanceId  \    -­‐-­‐output  text)  

aws  ec2  wait  instance-­‐running  -­‐-­‐instance-­‐ids  $instance_id  

Page 64: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

instance_id=$(aws  ec2  run-­‐instances  -­‐-­‐image-­‐id  ami-­‐12345  \    -­‐-­‐query  Reservations[].Instances[].InstanceId  \    -­‐-­‐output  text)  

aws  ec2  wait  instance-­‐running  -­‐-­‐instance-­‐ids  $instance_id  

ec2-waiters.sh

subcommand

Describe-instances options

waiter name

Page 65: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

Advanced Scenarios Looking at advanced AWS CLI features

Page 66: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

Templates

Page 67: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

The AWS CLI is data driven

Page 68: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

Implementation Details JSON Models

Page 69: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

Implementation Details JSON Models

Page 70: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

Implementation Details JSON Models

Page 71: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

aws  ec2  run-­‐instances  -­‐-­‐cli-­‐input-­‐json  file://arguments.json  

Page 72: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

aws  ec2  run-­‐instances  -­‐-­‐generate-­‐cli-­‐skeleton  

Page 73: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

Demo

Creating and using JSON templates

Page 74: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

Credential Providers

Page 75: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

Credential Providers

Page 76: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

Credential Providers

Page 77: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

Credential Providers

Page 78: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

Credential Providers

Page 79: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

Credential Providers

Page 80: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

Delegate access to AWS resources using AWS Identity and Access Management (IAM) roles

Page 81: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

IAM Roles

Production Development

Page 82: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

IAM Roles

Production Development

Page 83: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

v

IAM Roles

Production Development

Role Policy

Trust Policy

role

Page 84: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

IAM Roles

Production Development

AssumeRole

AWS Security Token Service

role

Page 85: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

IAM Roles

Production Development

AssumeRole

AWS Security Token Service

role

token

Page 86: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

IAM Roles

Production Development

AssumeRole

AWS Security Token Service

role

token

Page 87: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

aws  configure  set  profile.prodrole.source_profile  dev  

aws  configure  set  profile.prodrole.role_arn  arn:aws:iam…  

configure-role.sh

Page 88: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

~/.aws/credentials ~/.aws/config [dev] aws_access_key_id = foo aws_secret_access_key = bar

[profile prodrole] role_arn = arn:aws:iam....... source_profile = dev

Page 89: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

~/.aws/credentials ~/.aws/config [dev] aws_access_key_id = foo aws_secret_access_key = bar

[profile prodrole] role_arn = arn:aws:iam source_profile = dev

Page 90: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

Demo

Using roles with the AWS CLI

Page 91: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

Amazon S3 Streaming

Page 92: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

aws  s3  cp

Page 93: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

We want to avoid disk

Page 94: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

aws  s3  cp  –  s3://bucket/key

Page 95: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

aws  s3  cp  s3://bucket/key  -­‐

Page 96: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

Compress

Page 97: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

aws  s3  cp  s3://bucket/key  -­‐  |  \  bzip2  -­‐-­‐best  |  \    aws  s3  cp  -­‐  s3://bucket/key.bz2

Page 98: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

Summary

Page 99: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

Wrapping Up

•  Configuration •  Waiters •  Query

•  Templates •  Credential Providers •  Amazon S3 Streaming

Page 100: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

For More Information

https://github.com/aws/aws-cli http://docs.aws.amazon.com/cli/latest/userguide/ https://forums.aws.amazon.com/forum.jspa?forumID=150 http://docs.aws.amazon.com/cli/latest/reference/ http://jmespath.org/

Page 101: Deep Dive: AWS Command Line Interface - Amazon S3and...Deep Dive: AWS Command Line Interface Martin Elwin . CRASH COURSE Intro to the AWS CLI FOUNDATION ADVANCED SCENARIOS Exploring

LONDON

Martin Elwin [email protected]