CLI
AWS CLI Basics
Assume a Role
Edit ~/.aws/config
to include:
[profile <rolename>]
role_arn = arn:aws:iam::<acc_id>:role/<rolename>
source_profile = default
This assigns an IAM user with credentials and permissions to assume the role of <rolename>
source_profile
is the AWS CLI profile that has access to the role at the command line who can invoke it.
Assume Role Policies
The "giver" need the following policy:
The "taker" needs the following policy:
MFA with AssumeRole
The "giver" policy:
Then the "taker" in AWS CLI should add the configuration:
Create Security Group
Create Key Pair
Run an EC2 instance
To get the public IP of the instance:
Filters
The --filters
parameter can be used to specify particular types of instances to describe, which help automate large queries across many systems in the environment. Examples:
aws ec2 describe-instances --filters "Name=instance-type,Values=m1.small"
aws ec2 describe-instances --filters "Name=tag-key,Values=Quarantine"
These filters can also be represented in JSON format:
Then we can query using:
aws ec2 describe-instances --filters file://filters.json
Skeleton:
aws ec2 run-instances --generate-cli-skeleton > RunInstances.json
AWS CLI Output formats
JSON
text
table
We can change the config in the config file ~/.aws/config
:
We can also define in the ENV VAR
Or within the command:
Last updated