Top Banner
©2015, Amazon Web Services, Inc. or its affiliates. All rights reserved. Deep Dive: AWS Command Line Interface Thomas Jones, Solutions Architect Kyle Lichtenberg, Solutions Architect
106
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Deep Dive: AWS Command Line Interface

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

Deep Dive: AWS Command Line Interface

Thomas Jones, Solutions Architect

Kyle Lichtenberg, Solutions Architect

Page 2: Deep Dive: AWS Command Line Interface

Crash

Course

Intro to the AWS CLI

FOUNDATION ADVANCED

SCENARIOS

Exploring Key

FunctionalityLooking at Advanced

CLI Features

Page 3: Deep Dive: AWS Command Line Interface

Crash CourseIntro to the AWS CLI

Page 4: Deep Dive: AWS Command Line Interface

AWS Command Line Interface

Unified tool to manage your AWS services

Page 5: Deep Dive: AWS Command Line Interface

Why use the AWS CLI?

Scripting of actions

DevOps

Automation

Versioning

Speed

Programmatic input parameters

Reuse

Page 6: Deep Dive: AWS Command Line Interface

MSI (Windows)

Bundled (cross platform)

pip (cross platform)

Page 7: Deep Dive: AWS Command Line Interface

aws configure

Page 8: Deep Dive: AWS Command Line Interface

$ aws ec2 describe-instances

Service (command) Operation (subcommand)

Page 9: Deep Dive: AWS Command Line Interface

$ aws iam list-access-keys

Service (command) Operation (subcommand)

Page 10: Deep Dive: AWS Command Line Interface

{"Places": [

{ "City": "Seattle",

"State": "WA" }, {

"City": ”Las Vegas","State": "NV"

} ]

}

--output JSON

Page 11: Deep Dive: AWS Command Line Interface

PLACES Seattle WAPLACES Las Vegas NV

--output text

Page 12: Deep Dive: AWS Command Line Interface

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

--output table

Page 13: Deep Dive: AWS Command Line Interface

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 14: Deep Dive: AWS Command Line Interface

Demo

Basic AWS CLI Usage

Page 15: Deep Dive: AWS Command Line Interface

FoundationExploring Key Functionality

Page 16: Deep Dive: AWS Command Line Interface

Configuration

Page 17: Deep Dive: AWS Command Line Interface

aws configure

Page 18: Deep Dive: AWS Command Line Interface

aws configure

AWS access key ID [**ABCD]:

AWS secret access key [****************EFGH]:

Default region name [us-west-2]:

Default output format [None]:

Page 19: Deep Dive: AWS Command Line Interface

aws configure <subcommand>

Page 20: Deep Dive: AWS Command Line Interface

aws configure <subcommand>

list - list common configuration sources

get - get the value of a single config varset - set the value of a single config var

Page 21: Deep Dive: AWS Command Line Interface

aws configure get region

Page 22: Deep Dive: AWS Command Line Interface

aws configure set profile.prod.region us-west-2

Page 23: Deep Dive: AWS Command Line Interface

A profile is a group of configuration values

Page 24: Deep Dive: AWS Command Line Interface

aws configure --profile prod

Page 25: Deep Dive: AWS Command Line Interface

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

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

Page 27: Deep Dive: AWS Command Line Interface

aws configure set profile.prod.aws_access_key_id foo

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

Page 28: Deep Dive: AWS Command Line Interface

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

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

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

aws configure set profile.prod.region uswest2

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

[prod]

aws_access_key_id = foo

aws_secret_access_key = bar

Page 32: Deep Dive: AWS Command Line Interface

aws configure set profile.prod.region uswest2

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

[prod]

aws_access_key_id = foo

aws_secret_access_key = bar

[profile prod]

region = us-west-2

Page 33: Deep Dive: AWS Command Line Interface

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 = us-west-2

Page 34: Deep Dive: AWS Command Line Interface

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 = us-west-2

output = text

Page 35: Deep Dive: AWS Command Line Interface

create-new-user.sh

Page 36: Deep Dive: AWS Command Line Interface

create-new-user.sh

Page 37: Deep Dive: AWS Command Line Interface

create-new-user.sh

Page 38: Deep Dive: AWS Command Line Interface

create-new-user.sh

Page 39: Deep Dive: AWS Command Line Interface

create-new-user.sh

Page 40: Deep Dive: AWS Command Line Interface

create-new-user.sh

Page 41: Deep Dive: AWS Command Line Interface

Use the aws configure

suite of subcommands

Page 42: Deep Dive: AWS Command Line Interface

Query

Page 43: Deep Dive: AWS Command Line Interface
Page 44: Deep Dive: AWS Command Line Interface

Implementation Details --query Processing

Page 45: Deep Dive: AWS Command Line Interface

Implementation Details --query Processing

Page 46: Deep Dive: AWS Command Line Interface

Implementation Details --query Processing

Page 47: Deep Dive: AWS Command Line Interface

Implementation Details --query Processing

Page 48: Deep Dive: AWS Command Line Interface

Implementation Details --query Processing

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

Page 49: Deep Dive: AWS Command Line Interface

Implementation Details --query Processing

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

Page 50: Deep Dive: AWS Command Line Interface

Implementation Details --query Processing

Page 51: Deep Dive: AWS Command Line Interface

Implementation Details --query Processing

Page 52: Deep Dive: AWS Command Line Interface

http://jmespath.org

A Query Language for JSON

Page 53: Deep Dive: AWS Command Line Interface

Demo

JMESPATH

Page 54: Deep Dive: AWS Command Line Interface

http://jmespath.org

A Query Language for JSON

Page 55: Deep Dive: AWS Command Line Interface

Waiters

Page 56: Deep Dive: AWS Command Line Interface

Amazon EC2 Instance State Transitions

Page 57: Deep Dive: AWS Command Line Interface

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

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 59: Deep Dive: AWS Command Line Interface

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 60: Deep Dive: AWS Command Line Interface

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 61: Deep Dive: AWS Command Line Interface

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 62: Deep Dive: AWS Command Line Interface

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 63: Deep Dive: AWS Command Line Interface

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

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

subcommand

Describe-instances options

waiter name

Page 65: Deep Dive: AWS Command Line Interface

Advanced ScenariosLooking at advanced AWS CLI features

Page 66: Deep Dive: AWS Command Line Interface

Templates

Page 67: Deep Dive: AWS Command Line Interface

The AWS CLI is data driven

Page 68: Deep Dive: AWS Command Line Interface

Implementation Details JSON Models

Page 69: Deep Dive: AWS Command Line Interface

Implementation Details JSON Models

Page 70: Deep Dive: AWS Command Line Interface

Implementation Details JSON Models

Page 71: Deep Dive: AWS Command Line Interface

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

Page 72: Deep Dive: AWS Command Line Interface

What else can we do?

Page 73: Deep Dive: AWS Command Line Interface

aws ec2 run‐instances –generate-cli-skeleton

Page 74: Deep Dive: AWS Command Line Interface

Demo

Creating and using JSON templates

Page 75: Deep Dive: AWS Command Line Interface

Credential Providers

Page 76: Deep Dive: AWS Command Line Interface

Credential Providers

Page 77: Deep Dive: AWS Command Line Interface

Credential Providers

Page 78: Deep Dive: AWS Command Line Interface

Credential Providers

Page 79: Deep Dive: AWS Command Line Interface

Credential Providers

Page 80: Deep Dive: AWS Command Line Interface

Credential Providers

Page 81: Deep Dive: AWS Command Line Interface

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

Page 82: Deep Dive: AWS Command Line Interface

IAM Roles

Production Development

Page 83: Deep Dive: AWS Command Line Interface

IAM Roles

Production Development

Page 84: Deep Dive: AWS Command Line Interface

IAM Roles

Production Development

Role

Policy

Trust Policy

role

Page 85: Deep Dive: AWS Command Line Interface

IAM Roles

Production Development

AssumeRole

AWS Security

Token Service

role

Page 86: Deep Dive: AWS Command Line Interface

IAM Roles

Production Development

AssumeRole

AWS Security

Token Service

role

token

Page 87: Deep Dive: AWS Command Line Interface

IAM Roles

Production Development

AssumeRole

AWS Security

Token Service

role

token

Page 88: Deep Dive: AWS Command Line Interface

aws configure set profile.prodrole.source_profile dev

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

configure-role.sh

Page 89: Deep Dive: AWS Command Line Interface

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

[profile prodrole]

role_arn = arn:aws:iam

source_profile = dev

Page 90: Deep Dive: AWS Command Line Interface

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

[profile prodrole]

role_arn = arn:aws:iam

source_profile = dev

Page 91: Deep Dive: AWS Command Line Interface

Demo

Using roles with the AWS CLI

Page 92: Deep Dive: AWS Command Line Interface

Amazon S3 Streaming

Page 93: Deep Dive: AWS Command Line Interface

aws s3 ls s3://mybucket

Page 94: Deep Dive: AWS Command Line Interface

aws s3 sync myfolder s3://mybucket/myfolder

Page 95: Deep Dive: AWS Command Line Interface

aws s3 cp myfolder s3://mybucket/myfolder --recursive

Page 96: Deep Dive: AWS Command Line Interface

aws s3 cp

Page 97: Deep Dive: AWS Command Line Interface

We want to avoid disk

Page 98: Deep Dive: AWS Command Line Interface

aws s3 cp – s3://bucket/key

Page 99: Deep Dive: AWS Command Line Interface

aws s3 cp s3://bucket/key -

Page 100: Deep Dive: AWS Command Line Interface

Compress

Page 101: Deep Dive: AWS Command Line Interface

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

Page 102: Deep Dive: AWS Command Line Interface

Summary

Page 103: Deep Dive: AWS Command Line Interface

Wrapping Up

• Configuration

• Waiters

• Query

• Templates

• Credential Providers

• Amazon S3 Streaming

Page 104: Deep Dive: AWS Command Line Interface

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 105: Deep Dive: AWS Command Line Interface

Your Feedback is Important to AWSPlease complete the session evaluation. Tell us what you think!

Page 106: Deep Dive: AWS Command Line Interface

CHICAGO