Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
rb:aws-cli [18/12/2018 14:20]
andrew [Initial install]
rb:aws-cli [25/04/2019 10:01] (current)
andrew [Setting up roles]
Line 115: Line 115:
 </​code>​ </​code>​
  
 +
 +==== Errors ====
 +
 +<​code>​
 +$ aws ec2 describe-instances --profile nonprod_admin
 +
 +An error occurred (InvalidClientTokenId) when calling the AssumeRole operation: The security token included in the request is invalid.
 +$
 +</​code>​
 +
 +This was solved by updating the ''​aws_access_key_id''​ and ''​aws_secret_access_key''​ in ~/​.aws/​credentials.
 +As it said "The security token included in the request is invalid."​ Obvious in hindsight.
 +===== Using roles and profiles with Boto3 =====
 +
 +''​boto3''​ is Amazon'​s python library to interface with the aws cli commands.
 +
 +A client needs to be set up, and for local cli usage, this needs to be linked with a profile as set above.
 +
 +<code python>
 +#​!/​usr/​bin/​env python
 +
 +import boto3
 +
 +profile = '​nonprod_admin'​
 +
 +# Create ec2 client
 +session = boto3.session.Session(profile_name=profile)
 +ec2 = session.client('​ec2'​)
 +
 +# Create SQS client
 +session = boto3.session.Session(profile_name=profile)
 +sqs = session.client('​sqs'​)
 +
 +</​code>​
 +
 +This client (ec2, sqs etc) can be used to set or retreive information as the user in the profile:-
 +
 +<code python>
 +AMIResponse = ec2.describe_images(Filters=[{'​Name':​ '​name',​ '​Values':​ [Regex]}, ], Owners=['​self'​])
 +</​code>​
  
 ===== AWS CodeCommit ===== ===== AWS CodeCommit =====

rb/aws-cli.1545142826.txt.gz ยท Last modified: 18/12/2018 14:20 by andrew