SlideShare ist ein Scribd-Unternehmen logo
1 von 109
Downloaden Sie, um offline zu lesen
Masterclass
Advanced Usage of the AWS CLI
Danilo Poccia
AWS Technical Evangelist
@danilop
danilop
Masterclass
A technical deep dive beyond the basics

Help educate you on how to get the best from AWS technologies

Show you how things work and how to get things done

Broaden your knowledge in ~45 minutes
Crash Course Foundation Advanced Scenarios
Intro to the AWS CLI Exploring Key Functionality LookingatAdvancedCLIFeatures
Novice
Proficient
AdvancedCrash Course
Intro to the AWS CLI
AWS Command Line Interface
Unified tool to manage your AWS services
MSI (Windows)
Bundled (cross platform)
pip (cross platform)
aws	
  configure
$	
  aws	
  ec2	
  describe-­‐instances
service (command) operation (subcommand)
$	
  aws	
  iam	
  list-­‐access-­‐keys
service (command) operation (subcommand)
--output json
{	
  
	
  	
  	
  	
  "Places":	
  [	
  
	
  	
  	
  	
  	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "City":	
  "Seattle",	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "State":	
  "WA"	
  
	
  	
  	
  	
  	
  	
  	
  	
  },	
  
	
  	
  	
  	
  	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "City":	
  "Las	
  Vegas",	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "State":	
  "NV"	
  
	
  	
  	
  	
  	
  	
  	
  	
  }	
  
	
  	
  	
  	
  ]	
  
}
--output text
PLACES	
  	
  Seattle	
  	
  	
  WA	
  
PLACES	
  	
  Las	
  Vegas	
  NV
--output table
-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐	
  
|	
  	
  	
  	
  SomeOperationName	
  	
  	
  |	
  
+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+	
  
||	
  	
  	
  	
  	
  	
  	
  	
  Places	
  	
  	
  	
  	
  	
  	
  	
  ||	
  
|+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+|	
  
||	
  	
  	
  	
  City	
  	
  	
  	
  |	
  	
  State	
  	
  ||	
  
|+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+|	
  
||	
  	
  Seattle	
  	
  	
  |	
  	
  WA	
  	
  	
  	
  	
  ||	
  
||	
  	
  Las	
  Vegas	
  |	
  	
  NV	
  	
  	
  	
  	
  ||	
  
|+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+|
All Outputs
{	
  
	
  	
  	
  	
  "Places":	
  [	
  
	
  	
  	
  	
  	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "City":	
  "Seattle",	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "State":	
  "WA"	
  
	
  	
  	
  	
  	
  	
  	
  	
  },	
  
	
  	
  	
  	
  	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "City":	
  "Las	
  Vegas",	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "State":	
  "NV"	
  
	
  	
  	
  	
  	
  	
  	
  	
  }	
  
	
  	
  	
  	
  ]	
  
}
PLACES	
   Seattle	
  	
  	
  	
  WA	
  
PLACES	
   Las	
  Vegas	
  	
  NV
-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐	
  
|	
  	
  	
  	
  SomeOperationName	
  	
  	
  |	
  
+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+	
  
||	
  	
  	
  	
  	
  	
  	
  	
  Places	
  	
  	
  	
  	
  	
  	
  	
  ||	
  
|+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+|	
  
||	
  	
  	
  	
  City	
  	
  	
  	
  |	
  	
  State	
  	
  ||	
  
|+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+|	
  
||	
  	
  Seattle	
  	
  	
  |	
  	
  WA	
  	
  	
  	
  	
  ||	
  
||	
  	
  Las	
  Vegas	
  |	
  	
  NV	
  	
  	
  	
  	
  ||	
  
|+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+|
JSON Text Table
Basic AWS CLI Usage
DEMO
Novice
Proficient
AdvancedFoundation
Exploring Key Functionality
Configuration
aws	
  configure
aws	
  configure
AWS	
  Access	
  Key	
  ID	
  [**ABCD]:	
  
AWS	
  Secret	
  Access	
  Key	
  [****************EFGH]:	
  
Default	
  region	
  name	
  [us-­‐west-­‐2]:	
  
Default	
  output	
  format	
  [None]:
aws	
  configure	
  <subcommand>
aws	
  configure	
  <subcommand>
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	
  get	
  region
aws	
  configure	
  set	
  profile.prod.region	
  us-­‐west-­‐2
A profile is a group of configuration values
aws	
  configure	
  -­‐-­‐profile	
  prod
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)
~/.aws/credentials ~/.aws/config
aws	
  configure	
  set	
  profile.prod.aws_access_key_id	
  foo
~/.aws/credentials ~/.aws/config
aws	
  configure	
  set	
  profile.prod.aws_access_key_id	
  foo
[prod]
aws_access_key_id = foo
~/.aws/credentials ~/.aws/config
aws	
  configure	
  set	
  profile.prod.aws_secret_access_key	
  bar
[prod]
aws_access_key_id = foo
~/.aws/credentials ~/.aws/config
[prod]
aws_access_key_id = foo
aws_secret_access_key = bar
~/.aws/credentials ~/.aws/config
aws	
  configure	
  set	
  profile.prod.aws_secret_access_key	
  bar
aws	
  configure	
  set	
  profile.prod.region	
  us-­‐west-­‐2
[prod]
aws_access_key_id = foo
aws_secret_access_key = bar
~/.aws/credentials ~/.aws/config
[profile prod]
region = us-west-2
[prod]
aws_access_key_id = foo
aws_secret_access_key = bar
~/.aws/credentials ~/.aws/config
aws	
  configure	
  set	
  profile.prod.region	
  us-­‐west-­‐2
aws	
  configure	
  set	
  profile.prod.output	
  text
[profile prod]
region = us-west-2
[prod]
aws_access_key_id = foo
aws_secret_access_key = bar
~/.aws/credentials ~/.aws/config
[profile prod]
region = us-west-2
output = text
[prod]
aws_access_key_id = foo
aws_secret_access_key = bar
~/.aws/credentials ~/.aws/config
aws	
  configure	
  set	
  profile.prod.output	
  text
create-new-user.sh
#!/bin/bash	
  
#	
  Create	
  a	
  new	
  user	
  and	
  create	
  a	
  new	
  profile.	
  
aws	
  iam	
  create-­‐user	
  -­‐-­‐user-­‐name	
  masterclass-­‐user	
  
credentials=$(aws	
  iam	
  create-­‐access-­‐key	
  -­‐-­‐user-­‐name	
  masterclass-­‐user	
  	
  
	
  	
  	
  	
  -­‐-­‐query	
  'AccessKey.[AccessKeyId,SecretAccessKey]'	
  	
  
	
  	
  	
  	
  -­‐-­‐output	
  text)	
  
access_key_id=$(echo	
  $credentials	
  |	
  cut	
  -­‐d'	
  '	
  -­‐f	
  1)	
  
secret_access_key=$(echo	
  $credentials	
  |	
  cut	
  -­‐d'	
  '	
  -­‐f	
  2)	
  
aws	
  configure	
  set	
  profile.masterclass.aws_access_key_id	
  "$access_key_id"	
  
aws	
  configure	
  set	
  profile.masterclass.secret_access_key	
  "$secret_access_key"	
  
create-new-user.sh
#!/bin/bash	
  
#	
  Create	
  a	
  new	
  user	
  and	
  create	
  a	
  new	
  profile.	
  
aws	
  iam	
  create-­‐user	
  -­‐-­‐user-­‐name	
  masterclass-­‐user	
  
credentials=$(aws	
  iam	
  create-­‐access-­‐key	
  -­‐-­‐user-­‐name	
  masterclass-­‐user	
  	
  
	
  	
  	
  	
  -­‐-­‐query	
  'AccessKey.[AccessKeyId,SecretAccessKey]'	
  	
  
	
  	
  	
  	
  -­‐-­‐output	
  text)	
  
access_key_id=$(echo	
  $credentials	
  |	
  cut	
  -­‐d'	
  '	
  -­‐f	
  1)	
  
secret_access_key=$(echo	
  $credentials	
  |	
  cut	
  -­‐d'	
  '	
  -­‐f	
  2)	
  
aws	
  configure	
  set	
  profile.masterclass.aws_access_key_id	
  "$access_key_id"	
  
aws	
  configure	
  set	
  profile.masterclass.secret_access_key	
  "$secret_access_key"	
  
create-new-user.sh
#!/bin/bash	
  
#	
  Create	
  a	
  new	
  user	
  and	
  create	
  a	
  new	
  profile.	
  
aws	
  iam	
  create-­‐user	
  -­‐-­‐user-­‐name	
  masterclass-­‐user	
  
credentials=$(aws	
  iam	
  create-­‐access-­‐key	
  -­‐-­‐user-­‐name	
  masterclass-­‐user	
  	
  
	
  	
  	
  	
  -­‐-­‐query	
  'AccessKey.[AccessKeyId,SecretAccessKey]'	
  	
  
	
  	
  	
  	
  -­‐-­‐output	
  text)	
  
access_key_id=$(echo	
  $credentials	
  |	
  cut	
  -­‐d'	
  '	
  -­‐f	
  1)	
  
secret_access_key=$(echo	
  $credentials	
  |	
  cut	
  -­‐d'	
  '	
  -­‐f	
  2)	
  
aws	
  configure	
  set	
  profile.masterclass.aws_access_key_id	
  "$access_key_id"	
  
aws	
  configure	
  set	
  profile.masterclass.secret_access_key	
  "$secret_access_key"	
  
create-new-user.sh
#!/bin/bash	
  
#	
  Create	
  a	
  new	
  user	
  and	
  create	
  a	
  new	
  profile.	
  
aws	
  iam	
  create-­‐user	
  -­‐-­‐user-­‐name	
  masterclass-­‐user	
  
credentials=$(aws	
  iam	
  create-­‐access-­‐key	
  -­‐-­‐user-­‐name	
  masterclass-­‐user	
  	
  
	
  	
  	
  	
  -­‐-­‐query	
  'AccessKey.[AccessKeyId,SecretAccessKey]'	
  	
  
	
  	
  	
  	
  -­‐-­‐output	
  text)	
  
access_key_id=$(echo	
  $credentials	
  |	
  cut	
  -­‐d'	
  '	
  -­‐f	
  1)	
  
secret_access_key=$(echo	
  $credentials	
  |	
  cut	
  -­‐d'	
  '	
  -­‐f	
  2)	
  
aws	
  configure	
  set	
  profile.masterclass.aws_access_key_id	
  "$access_key_id"	
  
aws	
  configure	
  set	
  profile.masterclass.secret_access_key	
  "$secret_access_key"	
  
create-new-user.sh
#!/bin/bash	
  
#	
  Create	
  a	
  new	
  user	
  and	
  create	
  a	
  new	
  profile.	
  
aws	
  iam	
  create-­‐user	
  -­‐-­‐user-­‐name	
  masterclass-­‐user	
  
credentials=$(aws	
  iam	
  create-­‐access-­‐key	
  -­‐-­‐user-­‐name	
  masterclass-­‐user	
  	
  
	
  	
  	
  	
  -­‐-­‐query	
  'AccessKey.[AccessKeyId,SecretAccessKey]'	
  	
  
	
  	
  	
  	
  -­‐-­‐output	
  text)	
  
access_key_id=$(echo	
  $credentials	
  |	
  cut	
  -­‐d'	
  '	
  -­‐f	
  1)	
  
secret_access_key=$(echo	
  $credentials	
  |	
  cut	
  -­‐d'	
  '	
  -­‐f	
  2)	
  
aws	
  configure	
  set	
  profile.masterclass.aws_access_key_id	
  "$access_key_id"	
  
aws	
  configure	
  set	
  profile.masterclass.secret_access_key	
  "$secret_access_key"	
  
create-new-user.sh
#!/bin/bash	
  
#	
  Create	
  a	
  new	
  user	
  and	
  create	
  a	
  new	
  profile.	
  
aws	
  iam	
  create-­‐user	
  -­‐-­‐user-­‐name	
  masterclass-­‐user	
  
credentials=$(aws	
  iam	
  create-­‐access-­‐key	
  -­‐-­‐user-­‐name	
  masterclass-­‐user	
  	
  
	
  	
  	
  	
  -­‐-­‐query	
  'AccessKey.[AccessKeyId,SecretAccessKey]'	
  	
  
	
  	
  	
  	
  -­‐-­‐output	
  text)	
  
access_key_id=$(echo	
  $credentials	
  |	
  cut	
  -­‐d'	
  '	
  -­‐f	
  1)	
  
secret_access_key=$(echo	
  $credentials	
  |	
  cut	
  -­‐d'	
  '	
  -­‐f	
  2)	
  
aws	
  configure	
  set	
  profile.masterclass.aws_access_key_id	
  "$access_key_id"	
  
aws	
  configure	
  set	
  profile.masterclass.secret_access_key	
  "$secret_access_key"	
  
Use the aws configure
suite of subcommands
Query
-­‐-­‐query	
  (string)	
  
A	
  JMESPath	
  query	
  to	
  use	
  in	
  filtering	
  the	
  response	
  data.
Implementation Details --query Processing
aws ec2 ...
parse params
HTTP request
parse response
display response
format response
Retry Pagination
Implementation Details --query Processing
aws ec2 ...
parse params
HTTP request
parse response
display response
format response
Retry Pagination
parse response
parse response body
apply --query
Implementation Details --query Processing
<ListUsersResponse	
  xmlns="...">	
  
	
  	
  <ListUsersResult>	
  
	
  	
  	
  	
  <Users>	
  
	
  	
  	
  	
  	
  	
  <member>	
  
	
  	
  	
  	
  	
  	
  	
  	
  <UserId>userid</UserId>	
  
	
  	
  	
  	
  	
  	
  	
  	
  <Path>/</Path>	
  
	
  	
  	
  	
  	
  	
  	
  	
  <UserName>james</UserName>	
  
	
  	
  	
  	
  	
  	
  	
  	
  <Arn>arn:aws:iam::..:user/james</Arn>	
  
	
  	
  	
  	
  	
  	
  	
  	
  <CreateDate>2013-­‐03-­‐09T23:36:32Z</CreateDate>	
  
	
  	
  	
  	
  	
  	
  </member>	
  
	
  	
  	
  	
  <Users>	
  
	
  	
  </ListUsersResult>	
  
<ListUsersResponse>	
  
Implementation Details --query Processing
{	
  
	
  	
  "Users":	
  [	
  
	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  "Arn":	
  "arn:aws:iam::...:user/james",	
  
	
  	
  	
  	
  	
  	
  "UserId":	
  "userid",	
  
	
  	
  	
  	
  	
  	
  "CreateDate":	
  "2013-­‐03-­‐09T23:36:32Z",	
  
	
  	
  	
  	
  	
  	
  "Path":	
  "/",	
  
	
  	
  	
  	
  	
  	
  "UserName":	
  "james"	
  
	
  	
  	
  	
  }	
  
	
  	
  ]	
  
}
Implementation Details --query Processing
-­‐-­‐query	
  Users[0].[UserName,Path,UserId]
{	
  
	
  	
  "Users":	
  [	
  
	
  	
  	
  	
  {	
  
	
  	
  	
  	
  	
  	
  "Arn":	
  "arn:aws:iam::...:user/james",	
  
	
  	
  	
  	
  	
  	
  "UserId":	
  "userid",	
  
	
  	
  	
  	
  	
  	
  "CreateDate":	
  "2013-­‐03-­‐09T23:36:32Z",	
  
	
  	
  	
  	
  	
  	
  "Path":	
  "/",	
  
	
  	
  	
  	
  	
  	
  "UserName":	
  "james"	
  
	
  	
  	
  	
  }	
  
	
  	
  ]	
  
}
Implementation Details --query Processing
[	
  
	
  	
  	
  	
  [	
  
	
  	
  	
  	
  	
  	
  	
  	
  "james",	
  "/",	
  "id"	
  
	
  	
  	
  	
  ],	
  
]
-­‐-­‐query	
  Users[0].[UserName,Path,UserId]
Implementation Details --query Processing
-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐	
  
|	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  ListUsers	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  |	
  
+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+	
  
|	
  	
  james	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  |	
  	
  /	
  |	
  	
  userid	
  	
  |	
  
+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+
Implementation Details --query Processing
aws ec2 ...
parse params
HTTP request
parse response
display response
format response
Retry Pagination
http://jmespath.org
A Query Language For JSON
Waiters
Amazon EC2 Instance State Transitions
pending
running
shutting-down
terminated
stopping stoppedrebooting Stop
Terminate
Reboot
Terminate
Start
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	
  
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	
  
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	
  
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	
  
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	
  
• No timeouts
• Failure states
• Hand-written code
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
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
waiter name
describe-instances options
Novice
Proficient
AdvancedAdvanced Scenarios
Looking at advanced AWS CLI features
Templates
The AWS CLI is data driven
Implementation Details JSON Models
"RunInstancesRequest":{	
  
	
  	
  "type":"structure",	
  
	
  	
  "required":[	
  
	
  	
  	
  	
  "ImageId",	
  
	
  	
  	
  	
  "MinCount",	
  
	
  	
  	
  	
  "MaxCount"	
  
	
  	
  ],	
  
	
  	
  "members":{	
  
	
  	
  	
  	
  "ImageId":{"shape":"String"},	
  
	
  	
  	
  	
  "MinCount":{"shape":"Integer"},	
  
	
  	
  	
  	
  "MaxCount":{"shape":"Integer"},	
  
	
  	
  	
  	
  "KeyName":{"shape":"String"},	
  
	
  	
  	
  	
  "SecurityGroups":{	
  
	
  	
  	
  	
  	
  	
  "shape":"SecurityGroupStringList",	
  
	
  	
  	
  	
  	
  	
  "locationName":"SecurityGroup"	
  
	
  	
  	
  	
  },	
  
Implementation Details JSON Models
"RunInstancesRequest":{	
  
	
  	
  "type":"structure",	
  
	
  	
  "required":[	
  
	
  	
  	
  	
  "ImageId",	
  
	
  	
  	
  	
  "MinCount",	
  
	
  	
  	
  	
  "MaxCount"	
  
	
  	
  ],	
  
	
  	
  "members":{	
  
	
  	
  	
  	
  "ImageId":{"shape":"String"},	
  
	
  	
  	
  	
  "MinCount":{"shape":"Integer"},	
  
	
  	
  	
  	
  "MaxCount":{"shape":"Integer"},	
  
	
  	
  	
  	
  "KeyName":{"shape":"String"},	
  
	
  	
  	
  	
  "SecurityGroups":{	
  
	
  	
  	
  	
  	
  	
  "shape":"SecurityGroupStringList",	
  
	
  	
  	
  	
  	
  	
  "locationName":"SecurityGroup"	
  
	
  	
  	
  	
  },	
  
-­‐-­‐image-­‐id
-­‐-­‐min-­‐count
-­‐-­‐max-­‐count
-­‐-­‐key-­‐name
-­‐-­‐security-­‐groups
Implementation Details JSON Models
"RunInstancesRequest":{	
  
	
  	
  "type":"structure",	
  
	
  	
  "required":[	
  
	
  	
  	
  	
  "ImageId",	
  
	
  	
  	
  	
  "MinCount",	
  
	
  	
  	
  	
  "MaxCount"	
  
	
  	
  ],	
  
	
  	
  "members":{	
  
	
  	
  	
  	
  "ImageId":{"shape":"String"},	
  
	
  	
  	
  	
  "MinCount":{"shape":"Integer"},	
  
	
  	
  	
  	
  "MaxCount":{"shape":"Integer"},	
  
	
  	
  	
  	
  "KeyName":{"shape":"String"},	
  
	
  	
  	
  	
  "SecurityGroups":{	
  
	
  	
  	
  	
  	
  	
  "shape":"SecurityGroupStringList",	
  
	
  	
  	
  	
  	
  	
  "locationName":"SecurityGroup"	
  
	
  	
  	
  	
  },	
  
{	
  
	
  	
  "ImageId":	
  "ami-­‐12345",	
  
	
  	
  "MinCount":	
  1,	
  
	
  	
  "MaxCount":	
  1,	
  
	
  	
  "KeyName":	
  "id_rsa",	
  
	
  	
  "SecurityGroups":	
  ["SSH",	
  "web"],	
  
}	
  
arguments.json
aws	
  ec2	
  run-­‐instances	
  -­‐-­‐cli-­‐input-­‐json	
  file://arguments.json
What else can we do?
aws	
  ec2	
  run-­‐instances	
  -­‐-­‐generate-­‐cli-­‐skeleton
Creating and using JSON templates
DEMO
Credential Providers
export	
  AWS_ACCESS_KEY_ID=...
~/.aws/credentials
~/.aws/configCredentialLocator
Amazon	
  EC2	
  
Instance	
  Metadata
CredentialLocator
export	
  AWS_ACCESS_KEY_ID=...
~/.aws/credentials
~/.aws/config
Amazon	
  EC2	
  
Instance	
  Metadata
CredentialLocator
export	
  AWS_ACCESS_KEY_ID=...
~/.aws/credentials
~/.aws/config
Amazon	
  EC2	
  
Instance	
  Metadata
CredentialLocator
export	
  AWS_ACCESS_KEY_ID=...
~/.aws/credentials
~/.aws/config
Amazon	
  EC2	
  
Instance	
  Metadata
CredentialLocator
export	
  AWS_ACCESS_KEY_ID=...
~/.aws/credentials
~/.aws/config
Amazon	
  EC2	
  
Instance	
  Metadata
export	
  AWS_ACCESS_KEY_ID=...
~/.aws/credentials
~/.aws/config
Amazon	
  EC2	
  
Instance	
  Metadata
CredentialLocator
AssumeRole
AWS Identity and Access Management (IAM) roles
Delegate access to AWS resources using
Production Development
Production Development
Role
Policy
Trust Policy
Production Development
AssumeRole
Production Development
AssumeRole
Production Development
AssumeRole
configure-role.sh
aws	
  configure	
  set	
  profile.prodrole.role_arn	
  arn:aws:iam...
aws	
  configure	
  set	
  profile.prodrole.source_profile	
  dev
~/.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
[dev]	
  
aws_access_key_id	
  =	
  foo	
  
aws_secret_access_key	
  =	
  bar
[profile	
  prodrole]	
  
role_arn	
  =	
  arn:aws:iam	
  
source_profile	
  =	
  dev
~/.aws/credentials ~/.aws/config
Amazon S3 Streaming
aws	
  s3	
  cp
We want to avoid disk
aws	
  s3	
  cp	
  -­‐	
  s3://bucket/key
aws	
  s3	
  cp	
  s3://bucket/key	
  -­‐
Compress
s3-compress.sh
aws	
  s3	
  cp	
  s3://bucket/key	
  -­‐	
  |	
  gzip	
  |	
  aws	
  s3	
  cp	
  -­‐	
  s3://bucket/key.gz
Amazon S3 Streaming
DEMO
Working in Parallel
Mapping one output to N AWS calls
Mapping one output to N AWS calls
$	
  aws	
  iam	
  list…
[
"a",
"b",
”c",
"d",
"e"
]
$	
  aws	
  iam	
  …	
  -­‐-­‐foo	
  <here>
$	
  aws	
  iam	
  …	
  -­‐-­‐foo	
  <here>
$	
  aws	
  iam	
  …	
  -­‐-­‐foo	
  <here>
$	
  aws	
  iam	
  …	
  -­‐-­‐foo	
  <here>
$	
  aws	
  iam	
  …	
  -­‐-­‐foo	
  <here>
Mapping one output to N AWS calls
for	
  name	
  in	
  $(aws	
  iam	
  list-­‐users	
  	
  
	
  	
  	
  	
  -­‐-­‐query	
  "Users[].[UserName]"	
  -­‐-­‐output	
  text);	
  do	
  
	
  	
  aws	
  iam	
  delete-­‐user	
  -­‐-­‐user-­‐name	
  "$name"	
  
done
Mapping one output to N AWS calls
for	
  name	
  in	
  $(aws	
  iam	
  list-­‐users	
  	
  
	
  	
  	
  	
  -­‐-­‐query	
  "Users[].[UserName]"	
  -­‐-­‐output	
  text);	
  do	
  
	
  	
  aws	
  iam	
  delete-­‐user	
  -­‐-­‐user-­‐name	
  "$name"	
  
done
User1	
  
User2	
  
User3	
  
User4	
  
User5
Mapping one output to N AWS calls
for	
  name	
  in	
  $(aws	
  iam	
  list-­‐users	
  	
  
	
  	
  	
  	
  -­‐-­‐query	
  "Users[].[UserName]"	
  -­‐-­‐output	
  text);	
  do	
  
	
  	
  aws	
  iam	
  delete-­‐user	
  -­‐-­‐user-­‐name	
  "$name"	
  
done
Mapping one output to N AWS calls
aws	
  iam	
  list-­‐users	
  -­‐-­‐query	
  "Users[].[UserName]"	
  -­‐-­‐output	
  text	
  |	
  
	
  	
  xargs	
  -­‐I	
  {}	
  -­‐P	
  10	
  aws	
  iam	
  delete-­‐user	
  -­‐-­‐user-­‐name	
  "{}"
Mapping one output to N AWS calls
aws	
  iam	
  list-­‐users	
  -­‐-­‐query	
  "Users[].[UserName]"	
  -­‐-­‐output	
  text	
  |	
  
	
  	
  xargs	
  -­‐I	
  {}	
  -­‐P	
  10	
  aws	
  iam	
  delete-­‐user	
  -­‐-­‐user-­‐name	
  "{}"
Mapping one output to N AWS calls
aws	
  iam	
  list-­‐users	
  -­‐-­‐query	
  "Users[].[UserName]"	
  -­‐-­‐output	
  text	
  |	
  
	
  	
  xargs	
  -­‐I	
  {}	
  -­‐P	
  10	
  aws	
  iam	
  delete-­‐user	
  -­‐-­‐user-­‐name	
  "{}"
Parallel
Mapping one output to N AWS calls
-­‐+=	
  72730	
  james	
  -­‐bash	
  
	
  	
  -­‐+-­‐	
  76343	
  james	
  xargs	
  -­‐I	
  {}	
  –P	
  9	
  aws	
  iam	
  delete-­‐user	
  -­‐-­‐user-­‐name	
  {}	
  
	
  	
  	
  	
  |-­‐-­‐-­‐	
  76348	
  james	
  aws	
  iam	
  delete-­‐user	
  -­‐-­‐user-­‐name	
  user1	
  
	
  	
  	
  	
  |-­‐-­‐-­‐	
  76349	
  james	
  aws	
  iam	
  delete-­‐user	
  -­‐-­‐user-­‐name	
  user2	
  
	
  	
  	
  	
  |-­‐-­‐-­‐	
  76350	
  james	
  aws	
  iam	
  delete-­‐user	
  -­‐-­‐user-­‐name	
  user3	
  
	
  	
  	
  	
  |-­‐-­‐-­‐	
  76351	
  james	
  aws	
  iam	
  delete-­‐user	
  -­‐-­‐user-­‐name	
  user4	
  
	
  	
  	
  	
  |-­‐-­‐-­‐	
  76352	
  james	
  aws	
  iam	
  delete-­‐user	
  -­‐-­‐user-­‐name	
  user5	
  
	
  	
  	
  	
  |-­‐-­‐-­‐	
  76353	
  james	
  aws	
  iam	
  delete-­‐user	
  -­‐-­‐user-­‐name	
  user6	
  
	
  	
  	
  	
  |-­‐-­‐-­‐	
  76354	
  james	
  aws	
  iam	
  delete-­‐user	
  -­‐-­‐user-­‐name	
  user7	
  
	
  	
  	
  	
  |-­‐-­‐-­‐	
  76355	
  james	
  aws	
  iam	
  delete-­‐user	
  -­‐-­‐user-­‐name	
  user8	
  
	
  	
  	
  	
  -­‐-­‐-­‐	
  76356	
  james	
  aws	
  iam	
  delete-­‐user	
  -­‐-­‐user-­‐name	
  user9
Mapping one output to N AWS calls
• Use a for loop for functions
• If you’re using xargs, use -­‐I	
  {}	
  
• Use xargs	
  –P	
  N	
  parallel execution
• Use “.[UserName]” instead of “.UserName” to get
newline separated output..	
  
• This works because nothing is written to stdout on error
Wrapping Up
• Configuration
• Waiters
• Query
• Templates
• Credential Providers
• Amazon S3 Streaming
For More Information
• https://github.com/aws/aws-cli
• http://docs.aws.amazon.com/cli/latest/userguide/
• http://docs.aws.amazon.com/cli/latest/reference/
• https://forums.aws.amazon.com/forum.jspa?forumID=150
• http://jmespath.org/
Masterclass
Advanced Usage of the AWS CLI
Danilo Poccia
AWS Technical Evangelist
@danilop
danilop

Weitere ähnliche Inhalte

Was ist angesagt?

Amazon Cloud Services and Zend Framework
Amazon Cloud Services and Zend FrameworkAmazon Cloud Services and Zend Framework
Amazon Cloud Services and Zend Framework
Shahar Evron
 
Using Amazon Simple Db With Rails
Using Amazon Simple Db With RailsUsing Amazon Simple Db With Rails
Using Amazon Simple Db With Rails
Akhil Bansal
 
Stratalux Cloud Formation and Chef Integration Presentation
Stratalux Cloud Formation and Chef Integration PresentationStratalux Cloud Formation and Chef Integration Presentation
Stratalux Cloud Formation and Chef Integration Presentation
Jeremy Przygode
 

Was ist angesagt? (20)

TLS305 Using DynamoDB with the AWS SDK for PHP - AWS re: Invent 2012
TLS305 Using DynamoDB with the AWS SDK for PHP - AWS re: Invent 2012TLS305 Using DynamoDB with the AWS SDK for PHP - AWS re: Invent 2012
TLS305 Using DynamoDB with the AWS SDK for PHP - AWS re: Invent 2012
 
Amazon Route53へのドメイン移管
Amazon Route53へのドメイン移管Amazon Route53へのドメイン移管
Amazon Route53へのドメイン移管
 
(DEV301) Automating AWS with the AWS CLI
(DEV301) Automating AWS with the AWS CLI(DEV301) Automating AWS with the AWS CLI
(DEV301) Automating AWS with the AWS CLI
 
AWS re:Invent 2016: The Effective AWS CLI User (DEV402)
AWS re:Invent 2016: The Effective AWS CLI User (DEV402)AWS re:Invent 2016: The Effective AWS CLI User (DEV402)
AWS re:Invent 2016: The Effective AWS CLI User (DEV402)
 
Amazon Web Services for PHP Developers
Amazon Web Services for PHP DevelopersAmazon Web Services for PHP Developers
Amazon Web Services for PHP Developers
 
ARC204 AWS Infrastructure Automation - AWS re: Invent 2012
ARC204 AWS Infrastructure Automation - AWS re: Invent 2012ARC204 AWS Infrastructure Automation - AWS re: Invent 2012
ARC204 AWS Infrastructure Automation - AWS re: Invent 2012
 
Mastering the AWS SDK for PHP (TLS306) | AWS re:Invent 2013
Mastering the AWS SDK for PHP (TLS306) | AWS re:Invent 2013Mastering the AWS SDK for PHP (TLS306) | AWS re:Invent 2013
Mastering the AWS SDK for PHP (TLS306) | AWS re:Invent 2013
 
Let us make clear the aws directconnect
Let us make clear the aws directconnectLet us make clear the aws directconnect
Let us make clear the aws directconnect
 
Ansible Assume AWS Role
Ansible Assume AWS RoleAnsible Assume AWS Role
Ansible Assume AWS Role
 
Immutable AWS Deployments with Packer and Jenkins
Immutable AWS Deployments with Packer and JenkinsImmutable AWS Deployments with Packer and Jenkins
Immutable AWS Deployments with Packer and Jenkins
 
Amazon Cloud Services and Zend Framework
Amazon Cloud Services and Zend FrameworkAmazon Cloud Services and Zend Framework
Amazon Cloud Services and Zend Framework
 
Assetic (Symfony Live Paris)
Assetic (Symfony Live Paris)Assetic (Symfony Live Paris)
Assetic (Symfony Live Paris)
 
Not your Grandma's XQuery
Not your Grandma's XQueryNot your Grandma's XQuery
Not your Grandma's XQuery
 
Using Amazon Simple Db With Rails
Using Amazon Simple Db With RailsUsing Amazon Simple Db With Rails
Using Amazon Simple Db With Rails
 
AWS CloudFormation Masterclass
AWS CloudFormation MasterclassAWS CloudFormation Masterclass
AWS CloudFormation Masterclass
 
XQuery Rocks
XQuery RocksXQuery Rocks
XQuery Rocks
 
Assetic (Zendcon)
Assetic (Zendcon)Assetic (Zendcon)
Assetic (Zendcon)
 
Play!ng with scala
Play!ng with scalaPlay!ng with scala
Play!ng with scala
 
Cloudformation101
Cloudformation101Cloudformation101
Cloudformation101
 
Stratalux Cloud Formation and Chef Integration Presentation
Stratalux Cloud Formation and Chef Integration PresentationStratalux Cloud Formation and Chef Integration Presentation
Stratalux Cloud Formation and Chef Integration Presentation
 

Andere mochten auch

Andere mochten auch (20)

Building Event-driven Serverless Apps
Building Event-driven Serverless AppsBuilding Event-driven Serverless Apps
Building Event-driven Serverless Apps
 
An Introduction to AWS IoT
An Introduction to AWS IoTAn Introduction to AWS IoT
An Introduction to AWS IoT
 
Event-driven (serverless) Applications
Event-driven (serverless) ApplicationsEvent-driven (serverless) Applications
Event-driven (serverless) Applications
 
Building Event-Driven Serverless Applications
Building Event-Driven Serverless ApplicationsBuilding Event-Driven Serverless Applications
Building Event-Driven Serverless Applications
 
Connecting the Unconnected: IoT Made Simple
Connecting the Unconnected: IoT Made SimpleConnecting the Unconnected: IoT Made Simple
Connecting the Unconnected: IoT Made Simple
 
Get Value from Your Data
Get Value from Your DataGet Value from Your Data
Get Value from Your Data
 
Get Value From Your Data
Get Value From Your DataGet Value From Your Data
Get Value From Your Data
 
Build a Server-less Event-driven Backend with AWS Lambda and Amazon API Gateway
Build a Server-less Event-driven Backend with AWS Lambda and Amazon API GatewayBuild a Server-less Event-driven Backend with AWS Lambda and Amazon API Gateway
Build a Server-less Event-driven Backend with AWS Lambda and Amazon API Gateway
 
Cloud-powered Mobile Apps
Cloud-powered Mobile AppsCloud-powered Mobile Apps
Cloud-powered Mobile Apps
 
Machine Learning for Developers
Machine Learning for DevelopersMachine Learning for Developers
Machine Learning for Developers
 
Data Analytics on AWS
Data Analytics on AWSData Analytics on AWS
Data Analytics on AWS
 
Build a Server-less Event-driven Backend with AWS Lambda and Amazon API Gateway
Build a Server-less Event-driven Backend with AWS Lambda and Amazon API GatewayBuild a Server-less Event-driven Backend with AWS Lambda and Amazon API Gateway
Build a Server-less Event-driven Backend with AWS Lambda and Amazon API Gateway
 
Amazon Aurora: Amazon’s New Relational Database Engine
Amazon Aurora: Amazon’s New Relational Database EngineAmazon Aurora: Amazon’s New Relational Database Engine
Amazon Aurora: Amazon’s New Relational Database Engine
 
Amazon Workspaces Master Class
Amazon Workspaces Master ClassAmazon Workspaces Master Class
Amazon Workspaces Master Class
 
Amazon WorkSpaces - Aadvanced Topics & Application Delivery
Amazon WorkSpaces - Aadvanced Topics & Application DeliveryAmazon WorkSpaces - Aadvanced Topics & Application Delivery
Amazon WorkSpaces - Aadvanced Topics & Application Delivery
 
(NET301) New Capabilities for Amazon Virtual Private Cloud
(NET301) New Capabilities for Amazon Virtual Private Cloud(NET301) New Capabilities for Amazon Virtual Private Cloud
(NET301) New Capabilities for Amazon Virtual Private Cloud
 
Building Event-Driven Serverless Applications - AWS - Danilo Poccia
Building Event-Driven Serverless Applications - AWS - Danilo PocciaBuilding Event-Driven Serverless Applications - AWS - Danilo Poccia
Building Event-Driven Serverless Applications - AWS - Danilo Poccia
 
Building a Scalable and Highly Available Web Service with AWS: A Live Demo
Building a Scalable and Highly Available Web Service with AWS: A Live DemoBuilding a Scalable and Highly Available Web Service with AWS: A Live Demo
Building a Scalable and Highly Available Web Service with AWS: A Live Demo
 
How & When to Use NoSQL at Websummit Dublin
How & When to Use NoSQL at Websummit DublinHow & When to Use NoSQL at Websummit Dublin
How & When to Use NoSQL at Websummit Dublin
 
Getting Started with AWS Mobile Services
Getting Started with AWS Mobile ServicesGetting Started with AWS Mobile Services
Getting Started with AWS Mobile Services
 

Ähnlich wie Masterclass Advanced Usage of the AWS CLI

Stack kicker devopsdays-london-2013
Stack kicker devopsdays-london-2013Stack kicker devopsdays-london-2013
Stack kicker devopsdays-london-2013
Simon McCartney
 

Ähnlich wie Masterclass Advanced Usage of the AWS CLI (20)

CLI.pptx
CLI.pptxCLI.pptx
CLI.pptx
 
The Best of Both Worlds: Implementing Hybrid IT with AWS (ENT218) | AWS re:In...
The Best of Both Worlds: Implementing Hybrid IT with AWS (ENT218) | AWS re:In...The Best of Both Worlds: Implementing Hybrid IT with AWS (ENT218) | AWS re:In...
The Best of Both Worlds: Implementing Hybrid IT with AWS (ENT218) | AWS re:In...
 
Deployment and Management on AWS:
 A Deep Dive on Options and Tools
Deployment and Management on AWS:
 A Deep Dive on Options and ToolsDeployment and Management on AWS:
 A Deep Dive on Options and Tools
Deployment and Management on AWS:
 A Deep Dive on Options and Tools
 
Burn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websitesBurn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websites
 
스크립트로 Aws 서비스 자동화 하기 20161121 slideshare
스크립트로 Aws 서비스 자동화 하기 20161121 slideshare스크립트로 Aws 서비스 자동화 하기 20161121 slideshare
스크립트로 Aws 서비스 자동화 하기 20161121 slideshare
 
Understanding OpenStack Deployments - PuppetConf 2014
Understanding OpenStack Deployments - PuppetConf 2014Understanding OpenStack Deployments - PuppetConf 2014
Understanding OpenStack Deployments - PuppetConf 2014
 
Web::Machine - Simpl{e,y} HTTP
Web::Machine - Simpl{e,y} HTTPWeb::Machine - Simpl{e,y} HTTP
Web::Machine - Simpl{e,y} HTTP
 
Integrating icinga2 and the HashiCorp suite
Integrating icinga2 and the HashiCorp suiteIntegrating icinga2 and the HashiCorp suite
Integrating icinga2 and the HashiCorp suite
 
Azure Expert Leading Camp UA - 2015
Azure Expert Leading Camp UA - 2015Azure Expert Leading Camp UA - 2015
Azure Expert Leading Camp UA - 2015
 
NodeConf OneShot Budapest — Production Ready Node.js by Nuno Job
NodeConf OneShot Budapest — Production Ready Node.js by Nuno JobNodeConf OneShot Budapest — Production Ready Node.js by Nuno Job
NodeConf OneShot Budapest — Production Ready Node.js by Nuno Job
 
An Introduction to Windows PowerShell
An Introduction to Windows PowerShellAn Introduction to Windows PowerShell
An Introduction to Windows PowerShell
 
Stack kicker devopsdays-london-2013
Stack kicker devopsdays-london-2013Stack kicker devopsdays-london-2013
Stack kicker devopsdays-london-2013
 
Puppet @ Seat
Puppet @ SeatPuppet @ Seat
Puppet @ Seat
 
AWS Study Group - Chapter 03 - Elasticity and Scalability Concepts [Solution ...
AWS Study Group - Chapter 03 - Elasticity and Scalability Concepts [Solution ...AWS Study Group - Chapter 03 - Elasticity and Scalability Concepts [Solution ...
AWS Study Group - Chapter 03 - Elasticity and Scalability Concepts [Solution ...
 
AWS Lambda with Serverless Framework and Java
AWS Lambda with Serverless Framework and JavaAWS Lambda with Serverless Framework and Java
AWS Lambda with Serverless Framework and Java
 
Powershell for Log Analysis and Data Crunching
 Powershell for Log Analysis and Data Crunching Powershell for Log Analysis and Data Crunching
Powershell for Log Analysis and Data Crunching
 
Monkey man
Monkey manMonkey man
Monkey man
 
How I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine Yard
How I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine YardHow I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine Yard
How I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine Yard
 
DevOps for the Enterprise: Virtual Office Hours
DevOps for the Enterprise: Virtual Office HoursDevOps for the Enterprise: Virtual Office Hours
DevOps for the Enterprise: Virtual Office Hours
 
Specification-Driven Development of REST APIs by Alexander Zinchuk
Specification-Driven Development of REST APIs by Alexander Zinchuk   Specification-Driven Development of REST APIs by Alexander Zinchuk
Specification-Driven Development of REST APIs by Alexander Zinchuk
 

Mehr von Danilo Poccia

Mehr von Danilo Poccia (15)

Amazon Elastic File System (Amazon EFS)
Amazon Elastic File System (Amazon EFS)Amazon Elastic File System (Amazon EFS)
Amazon Elastic File System (Amazon EFS)
 
AWS Mobile Hub Overview
AWS Mobile Hub OverviewAWS Mobile Hub Overview
AWS Mobile Hub Overview
 
Managing Containers at Scale
Managing Containers at ScaleManaging Containers at Scale
Managing Containers at Scale
 
Amazon API Gateway and AWS Lambda: Better Together
Amazon API Gateway and AWS Lambda: Better TogetherAmazon API Gateway and AWS Lambda: Better Together
Amazon API Gateway and AWS Lambda: Better Together
 
Amazon Aurora Let's Talk About Performance
Amazon Aurora Let's Talk About PerformanceAmazon Aurora Let's Talk About Performance
Amazon Aurora Let's Talk About Performance
 
Infrastructure as Code: Manage your Architecture with Git
Infrastructure as Code: Manage your Architecture with GitInfrastructure as Code: Manage your Architecture with Git
Infrastructure as Code: Manage your Architecture with Git
 
Infrastructure as Code: Manage your Architecture with Git
Infrastructure as Code: Manage your Architecture with GitInfrastructure as Code: Manage your Architecture with Git
Infrastructure as Code: Manage your Architecture with Git
 
Cloud-powered Cross-platform Mobile Apps on AWS
Cloud-powered Cross-platform Mobile Apps on AWSCloud-powered Cross-platform Mobile Apps on AWS
Cloud-powered Cross-platform Mobile Apps on AWS
 
Microservice Architecture on AWS using AWS Lambda and Docker Containers
Microservice Architecture on AWS using AWS Lambda and Docker ContainersMicroservice Architecture on AWS using AWS Lambda and Docker Containers
Microservice Architecture on AWS using AWS Lambda and Docker Containers
 
Microservices on AWS using AWS Lambda and Docker Containers
Microservices on AWS using AWS Lambda and Docker ContainersMicroservices on AWS using AWS Lambda and Docker Containers
Microservices on AWS using AWS Lambda and Docker Containers
 
AWS Lambda
AWS LambdaAWS Lambda
AWS Lambda
 
Building Cloud-powered Mobile Apps
Building Cloud-powered Mobile AppsBuilding Cloud-powered Mobile Apps
Building Cloud-powered Mobile Apps
 
Building Cloud-Powered Mobile Apps
Building Cloud-Powered Mobile AppsBuilding Cloud-Powered Mobile Apps
Building Cloud-Powered Mobile Apps
 
Building Cloud-powered Mobile Apps
Building Cloud-powered Mobile AppsBuilding Cloud-powered Mobile Apps
Building Cloud-powered Mobile Apps
 
Media Applications on AWS
Media Applications on AWSMedia Applications on AWS
Media Applications on AWS
 

Kürzlich hochgeladen

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 

Kürzlich hochgeladen (20)

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 
WSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AIWSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AI
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 

Masterclass Advanced Usage of the AWS CLI

  • 1. Masterclass Advanced Usage of the AWS CLI Danilo Poccia AWS Technical Evangelist @danilop danilop
  • 2. Masterclass A technical deep dive beyond the basics
 Help educate you on how to get the best from AWS technologies
 Show you how things work and how to get things done
 Broaden your knowledge in ~45 minutes
  • 3. Crash Course Foundation Advanced Scenarios Intro to the AWS CLI Exploring Key Functionality LookingatAdvancedCLIFeatures
  • 5. AWS Command Line Interface Unified tool to manage your AWS services
  • 6. MSI (Windows) Bundled (cross platform) pip (cross platform)
  • 8. $  aws  ec2  describe-­‐instances service (command) operation (subcommand)
  • 9. $  aws  iam  list-­‐access-­‐keys service (command) operation (subcommand)
  • 10. --output json {          "Places":  [                  {                          "City":  "Seattle",                          "State":  "WA"                  },                  {                          "City":  "Las  Vegas",                          "State":  "NV"                  }          ]   }
  • 11. --output text PLACES    Seattle      WA   PLACES    Las  Vegas  NV
  • 12. --output table -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐   |        SomeOperationName      |   +-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+   ||                Places                ||   |+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+|   ||        City        |    State    ||   |+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+|   ||    Seattle      |    WA          ||   ||    Las  Vegas  |    NV          ||   |+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+|
  • 13. All Outputs {          "Places":  [                  {                          "City":  "Seattle",                          "State":  "WA"                  },                  {                          "City":  "Las  Vegas",                          "State":  "NV"                  }          ]   } PLACES   Seattle        WA   PLACES   Las  Vegas    NV -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐   |        SomeOperationName      |   +-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+   ||                Places                ||   |+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+|   ||        City        |    State    ||   |+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+|   ||    Seattle      |    WA          ||   ||    Las  Vegas  |    NV          ||   |+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+| JSON Text Table
  • 14. Basic AWS CLI Usage DEMO
  • 18. aws  configure AWS  Access  Key  ID  [**ABCD]:   AWS  Secret  Access  Key  [****************EFGH]:   Default  region  name  [us-­‐west-­‐2]:   Default  output  format  [None]:
  • 20. aws  configure  <subcommand> list  - List common configuration sources get    - Get the value of a single config var set    - Set the value of a single config var
  • 22. aws  configure  set  profile.prod.region  us-­‐west-­‐2
  • 23. A profile is a group of configuration values
  • 25. 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)
  • 27. aws  configure  set  profile.prod.aws_access_key_id  foo ~/.aws/credentials ~/.aws/config
  • 28. aws  configure  set  profile.prod.aws_access_key_id  foo [prod] aws_access_key_id = foo ~/.aws/credentials ~/.aws/config
  • 29. aws  configure  set  profile.prod.aws_secret_access_key  bar [prod] aws_access_key_id = foo ~/.aws/credentials ~/.aws/config
  • 30. [prod] aws_access_key_id = foo aws_secret_access_key = bar ~/.aws/credentials ~/.aws/config aws  configure  set  profile.prod.aws_secret_access_key  bar
  • 31. aws  configure  set  profile.prod.region  us-­‐west-­‐2 [prod] aws_access_key_id = foo aws_secret_access_key = bar ~/.aws/credentials ~/.aws/config
  • 32. [profile prod] region = us-west-2 [prod] aws_access_key_id = foo aws_secret_access_key = bar ~/.aws/credentials ~/.aws/config aws  configure  set  profile.prod.region  us-­‐west-­‐2
  • 33. aws  configure  set  profile.prod.output  text [profile prod] region = us-west-2 [prod] aws_access_key_id = foo aws_secret_access_key = bar ~/.aws/credentials ~/.aws/config
  • 34. [profile prod] region = us-west-2 output = text [prod] aws_access_key_id = foo aws_secret_access_key = bar ~/.aws/credentials ~/.aws/config aws  configure  set  profile.prod.output  text
  • 35. create-new-user.sh #!/bin/bash   #  Create  a  new  user  and  create  a  new  profile.   aws  iam  create-­‐user  -­‐-­‐user-­‐name  masterclass-­‐user   credentials=$(aws  iam  create-­‐access-­‐key  -­‐-­‐user-­‐name  masterclass-­‐user            -­‐-­‐query  'AccessKey.[AccessKeyId,SecretAccessKey]'            -­‐-­‐output  text)   access_key_id=$(echo  $credentials  |  cut  -­‐d'  '  -­‐f  1)   secret_access_key=$(echo  $credentials  |  cut  -­‐d'  '  -­‐f  2)   aws  configure  set  profile.masterclass.aws_access_key_id  "$access_key_id"   aws  configure  set  profile.masterclass.secret_access_key  "$secret_access_key"  
  • 36. create-new-user.sh #!/bin/bash   #  Create  a  new  user  and  create  a  new  profile.   aws  iam  create-­‐user  -­‐-­‐user-­‐name  masterclass-­‐user   credentials=$(aws  iam  create-­‐access-­‐key  -­‐-­‐user-­‐name  masterclass-­‐user            -­‐-­‐query  'AccessKey.[AccessKeyId,SecretAccessKey]'            -­‐-­‐output  text)   access_key_id=$(echo  $credentials  |  cut  -­‐d'  '  -­‐f  1)   secret_access_key=$(echo  $credentials  |  cut  -­‐d'  '  -­‐f  2)   aws  configure  set  profile.masterclass.aws_access_key_id  "$access_key_id"   aws  configure  set  profile.masterclass.secret_access_key  "$secret_access_key"  
  • 37. create-new-user.sh #!/bin/bash   #  Create  a  new  user  and  create  a  new  profile.   aws  iam  create-­‐user  -­‐-­‐user-­‐name  masterclass-­‐user   credentials=$(aws  iam  create-­‐access-­‐key  -­‐-­‐user-­‐name  masterclass-­‐user            -­‐-­‐query  'AccessKey.[AccessKeyId,SecretAccessKey]'            -­‐-­‐output  text)   access_key_id=$(echo  $credentials  |  cut  -­‐d'  '  -­‐f  1)   secret_access_key=$(echo  $credentials  |  cut  -­‐d'  '  -­‐f  2)   aws  configure  set  profile.masterclass.aws_access_key_id  "$access_key_id"   aws  configure  set  profile.masterclass.secret_access_key  "$secret_access_key"  
  • 38. create-new-user.sh #!/bin/bash   #  Create  a  new  user  and  create  a  new  profile.   aws  iam  create-­‐user  -­‐-­‐user-­‐name  masterclass-­‐user   credentials=$(aws  iam  create-­‐access-­‐key  -­‐-­‐user-­‐name  masterclass-­‐user            -­‐-­‐query  'AccessKey.[AccessKeyId,SecretAccessKey]'            -­‐-­‐output  text)   access_key_id=$(echo  $credentials  |  cut  -­‐d'  '  -­‐f  1)   secret_access_key=$(echo  $credentials  |  cut  -­‐d'  '  -­‐f  2)   aws  configure  set  profile.masterclass.aws_access_key_id  "$access_key_id"   aws  configure  set  profile.masterclass.secret_access_key  "$secret_access_key"  
  • 39. create-new-user.sh #!/bin/bash   #  Create  a  new  user  and  create  a  new  profile.   aws  iam  create-­‐user  -­‐-­‐user-­‐name  masterclass-­‐user   credentials=$(aws  iam  create-­‐access-­‐key  -­‐-­‐user-­‐name  masterclass-­‐user            -­‐-­‐query  'AccessKey.[AccessKeyId,SecretAccessKey]'            -­‐-­‐output  text)   access_key_id=$(echo  $credentials  |  cut  -­‐d'  '  -­‐f  1)   secret_access_key=$(echo  $credentials  |  cut  -­‐d'  '  -­‐f  2)   aws  configure  set  profile.masterclass.aws_access_key_id  "$access_key_id"   aws  configure  set  profile.masterclass.secret_access_key  "$secret_access_key"  
  • 40. create-new-user.sh #!/bin/bash   #  Create  a  new  user  and  create  a  new  profile.   aws  iam  create-­‐user  -­‐-­‐user-­‐name  masterclass-­‐user   credentials=$(aws  iam  create-­‐access-­‐key  -­‐-­‐user-­‐name  masterclass-­‐user            -­‐-­‐query  'AccessKey.[AccessKeyId,SecretAccessKey]'            -­‐-­‐output  text)   access_key_id=$(echo  $credentials  |  cut  -­‐d'  '  -­‐f  1)   secret_access_key=$(echo  $credentials  |  cut  -­‐d'  '  -­‐f  2)   aws  configure  set  profile.masterclass.aws_access_key_id  "$access_key_id"   aws  configure  set  profile.masterclass.secret_access_key  "$secret_access_key"  
  • 41. Use the aws configure suite of subcommands
  • 42. Query
  • 43. -­‐-­‐query  (string)   A  JMESPath  query  to  use  in  filtering  the  response  data.
  • 44. Implementation Details --query Processing aws ec2 ... parse params HTTP request parse response display response format response Retry Pagination
  • 45. Implementation Details --query Processing aws ec2 ... parse params HTTP request parse response display response format response Retry Pagination parse response parse response body apply --query
  • 46. Implementation Details --query Processing <ListUsersResponse  xmlns="...">      <ListUsersResult>          <Users>              <member>                  <UserId>userid</UserId>                  <Path>/</Path>                  <UserName>james</UserName>                  <Arn>arn:aws:iam::..:user/james</Arn>                  <CreateDate>2013-­‐03-­‐09T23:36:32Z</CreateDate>              </member>          <Users>      </ListUsersResult>   <ListUsersResponse>  
  • 47. Implementation Details --query Processing {      "Users":  [          {              "Arn":  "arn:aws:iam::...:user/james",              "UserId":  "userid",              "CreateDate":  "2013-­‐03-­‐09T23:36:32Z",              "Path":  "/",              "UserName":  "james"          }      ]   }
  • 48. Implementation Details --query Processing -­‐-­‐query  Users[0].[UserName,Path,UserId] {      "Users":  [          {              "Arn":  "arn:aws:iam::...:user/james",              "UserId":  "userid",              "CreateDate":  "2013-­‐03-­‐09T23:36:32Z",              "Path":  "/",              "UserName":  "james"          }      ]   }
  • 49. Implementation Details --query Processing [          [                  "james",  "/",  "id"          ],   ] -­‐-­‐query  Users[0].[UserName,Path,UserId]
  • 50. Implementation Details --query Processing -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐   |                              ListUsers                              |   +-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+   |    james                                |    /  |    userid    |   +-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐+-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐+
  • 51. Implementation Details --query Processing aws ec2 ... parse params HTTP request parse response display response format response Retry Pagination
  • 54. Amazon EC2 Instance State Transitions pending running shutting-down terminated stopping stoppedrebooting Stop Terminate Reboot Terminate Start
  • 55. 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  
  • 56. 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  
  • 57. 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  
  • 58. 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  
  • 59. 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   • No timeouts • Failure states • Hand-written code
  • 60. 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
  • 61. 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 waiter name describe-instances options
  • 64. The AWS CLI is data driven
  • 65. Implementation Details JSON Models "RunInstancesRequest":{      "type":"structure",      "required":[          "ImageId",          "MinCount",          "MaxCount"      ],      "members":{          "ImageId":{"shape":"String"},          "MinCount":{"shape":"Integer"},          "MaxCount":{"shape":"Integer"},          "KeyName":{"shape":"String"},          "SecurityGroups":{              "shape":"SecurityGroupStringList",              "locationName":"SecurityGroup"          },  
  • 66. Implementation Details JSON Models "RunInstancesRequest":{      "type":"structure",      "required":[          "ImageId",          "MinCount",          "MaxCount"      ],      "members":{          "ImageId":{"shape":"String"},          "MinCount":{"shape":"Integer"},          "MaxCount":{"shape":"Integer"},          "KeyName":{"shape":"String"},          "SecurityGroups":{              "shape":"SecurityGroupStringList",              "locationName":"SecurityGroup"          },   -­‐-­‐image-­‐id -­‐-­‐min-­‐count -­‐-­‐max-­‐count -­‐-­‐key-­‐name -­‐-­‐security-­‐groups
  • 67. Implementation Details JSON Models "RunInstancesRequest":{      "type":"structure",      "required":[          "ImageId",          "MinCount",          "MaxCount"      ],      "members":{          "ImageId":{"shape":"String"},          "MinCount":{"shape":"Integer"},          "MaxCount":{"shape":"Integer"},          "KeyName":{"shape":"String"},          "SecurityGroups":{              "shape":"SecurityGroupStringList",              "locationName":"SecurityGroup"          },   {      "ImageId":  "ami-­‐12345",      "MinCount":  1,      "MaxCount":  1,      "KeyName":  "id_rsa",      "SecurityGroups":  ["SSH",  "web"],   }   arguments.json
  • 68. aws  ec2  run-­‐instances  -­‐-­‐cli-­‐input-­‐json  file://arguments.json
  • 69. What else can we do?
  • 70. aws  ec2  run-­‐instances  -­‐-­‐generate-­‐cli-­‐skeleton
  • 71. Creating and using JSON templates DEMO
  • 78. export  AWS_ACCESS_KEY_ID=... ~/.aws/credentials ~/.aws/config Amazon  EC2   Instance  Metadata CredentialLocator AssumeRole
  • 79. AWS Identity and Access Management (IAM) roles Delegate access to AWS resources using
  • 85. configure-role.sh aws  configure  set  profile.prodrole.role_arn  arn:aws:iam... aws  configure  set  profile.prodrole.source_profile  dev
  • 86. ~/.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
  • 87. [dev]   aws_access_key_id  =  foo   aws_secret_access_key  =  bar [profile  prodrole]   role_arn  =  arn:aws:iam   source_profile  =  dev ~/.aws/credentials ~/.aws/config
  • 90. We want to avoid disk
  • 91. aws  s3  cp  -­‐  s3://bucket/key
  • 92. aws  s3  cp  s3://bucket/key  -­‐
  • 94. s3-compress.sh aws  s3  cp  s3://bucket/key  -­‐  |  gzip  |  aws  s3  cp  -­‐  s3://bucket/key.gz
  • 97. Mapping one output to N AWS calls
  • 98. Mapping one output to N AWS calls $  aws  iam  list… [ "a", "b", ”c", "d", "e" ] $  aws  iam  …  -­‐-­‐foo  <here> $  aws  iam  …  -­‐-­‐foo  <here> $  aws  iam  …  -­‐-­‐foo  <here> $  aws  iam  …  -­‐-­‐foo  <here> $  aws  iam  …  -­‐-­‐foo  <here>
  • 99. Mapping one output to N AWS calls for  name  in  $(aws  iam  list-­‐users            -­‐-­‐query  "Users[].[UserName]"  -­‐-­‐output  text);  do      aws  iam  delete-­‐user  -­‐-­‐user-­‐name  "$name"   done
  • 100. Mapping one output to N AWS calls for  name  in  $(aws  iam  list-­‐users            -­‐-­‐query  "Users[].[UserName]"  -­‐-­‐output  text);  do      aws  iam  delete-­‐user  -­‐-­‐user-­‐name  "$name"   done User1   User2   User3   User4   User5
  • 101. Mapping one output to N AWS calls for  name  in  $(aws  iam  list-­‐users            -­‐-­‐query  "Users[].[UserName]"  -­‐-­‐output  text);  do      aws  iam  delete-­‐user  -­‐-­‐user-­‐name  "$name"   done
  • 102. Mapping one output to N AWS calls aws  iam  list-­‐users  -­‐-­‐query  "Users[].[UserName]"  -­‐-­‐output  text  |      xargs  -­‐I  {}  -­‐P  10  aws  iam  delete-­‐user  -­‐-­‐user-­‐name  "{}"
  • 103. Mapping one output to N AWS calls aws  iam  list-­‐users  -­‐-­‐query  "Users[].[UserName]"  -­‐-­‐output  text  |      xargs  -­‐I  {}  -­‐P  10  aws  iam  delete-­‐user  -­‐-­‐user-­‐name  "{}"
  • 104. Mapping one output to N AWS calls aws  iam  list-­‐users  -­‐-­‐query  "Users[].[UserName]"  -­‐-­‐output  text  |      xargs  -­‐I  {}  -­‐P  10  aws  iam  delete-­‐user  -­‐-­‐user-­‐name  "{}" Parallel
  • 105. Mapping one output to N AWS calls -­‐+=  72730  james  -­‐bash      -­‐+-­‐  76343  james  xargs  -­‐I  {}  –P  9  aws  iam  delete-­‐user  -­‐-­‐user-­‐name  {}          |-­‐-­‐-­‐  76348  james  aws  iam  delete-­‐user  -­‐-­‐user-­‐name  user1          |-­‐-­‐-­‐  76349  james  aws  iam  delete-­‐user  -­‐-­‐user-­‐name  user2          |-­‐-­‐-­‐  76350  james  aws  iam  delete-­‐user  -­‐-­‐user-­‐name  user3          |-­‐-­‐-­‐  76351  james  aws  iam  delete-­‐user  -­‐-­‐user-­‐name  user4          |-­‐-­‐-­‐  76352  james  aws  iam  delete-­‐user  -­‐-­‐user-­‐name  user5          |-­‐-­‐-­‐  76353  james  aws  iam  delete-­‐user  -­‐-­‐user-­‐name  user6          |-­‐-­‐-­‐  76354  james  aws  iam  delete-­‐user  -­‐-­‐user-­‐name  user7          |-­‐-­‐-­‐  76355  james  aws  iam  delete-­‐user  -­‐-­‐user-­‐name  user8          -­‐-­‐-­‐  76356  james  aws  iam  delete-­‐user  -­‐-­‐user-­‐name  user9
  • 106. Mapping one output to N AWS calls • Use a for loop for functions • If you’re using xargs, use -­‐I  {}   • Use xargs  –P  N  parallel execution • Use “.[UserName]” instead of “.UserName” to get newline separated output..   • This works because nothing is written to stdout on error
  • 107. Wrapping Up • Configuration • Waiters • Query • Templates • Credential Providers • Amazon S3 Streaming
  • 108. For More Information • https://github.com/aws/aws-cli • http://docs.aws.amazon.com/cli/latest/userguide/ • http://docs.aws.amazon.com/cli/latest/reference/ • https://forums.aws.amazon.com/forum.jspa?forumID=150 • http://jmespath.org/
  • 109. Masterclass Advanced Usage of the AWS CLI Danilo Poccia AWS Technical Evangelist @danilop danilop