AWS CLI

From SWKLS WIKI
Revision as of 17:59, 26 March 2020 by Unknown user (talk) (Created page with "==Multiple Profiles== Source: https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html#cli-quick-configuration-multi-profiles ===Default Profile=== Example of...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Multiple Profiles

Source: https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html#cli-quick-configuration-multi-profiles

Default Profile

Example of configuring AWS CLI before use:

$ aws configure AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY Default region name [None]: us-east-1 Default output format [None]: json

Creating Multiple Profiles

If you use the command shown in the previous section, the result is a single profile named default. You can create additional configurations that you can refer to with a name by specifying the --profile option and assigning a name. The following example creates a profile named produser. You can specify credentials from a completely different account and region than the other profiles. $ aws configure --profile produser AWS Access Key ID [None]: AKIAI44QH8DHBEXAMPLE AWS Secret Access Key [None]: je7MtGbClwBF/2Zp9Utk/h3yCo8nvbEXAMPLEKEY Default region name [None]: us-east-1 Default output format [None]: text Then, when you run a command, you can omit the --profile option and use the credentials and settings stored in the <default> profile.

$ aws s3 ls

Or you can specify a --profile <profilename> and use the credentials and settings stored under that name.

$ aws s3 ls --profile produser

To update any of your settings, simply run aws configure again (with or without the --profile parameter, depending on which profile you want to update) and enter new values as appropriate.

Notes on Various Commands aws lightsail get-instance-snapshots --query 'instanceSnapshots[?fromInstanceName==`Amazon_Linux-4GB-Virginia-1-swkls3`].name' --output table aws lightsail get-instance-snapshots --query 'instanceSnapshots[?fromInstanceName==`Amazon_Linux-4GB-Virginia-1-swkls3`]' --output table aws lightsail get-instance-snapshots --query 'instanceSnapshots[?fromInstanceName==`Amazon_Linux-4GB-Virginia-1-swkls3`].arn' --output table aws lightsail get-instance-snapshots --query 'instanceSnapshots[].[name]' aws lightsail get-instance-snapshots --query 'instanceSnapshots[]' aws lightsail get-instance-snapshots --query 'instanceSnapshots[].[fromInstanceName,name]' aws lightsail get-instance-snapshots --query 'instanceSnapshots[].[fromInstanceName,name]' --output table aws lightsail get-instance-snapshots --query 'instanceSnapshots[?].[fromInstanceName,name]' --output table aws lightsail get-instance-snapshots --query "sort_by(instanceSnapshots, &createdAt)[*].[fromInstanceName,name]" --output table aws lightsail get-instance-snapshots --query 'instanceSnapshots[?fromInstanceName==`${option.Instance}`].name' --output table aws lightsail get-instance --instance-name "Amazon_Linux-4GB-Virginia-1-swkls4" --query 'instance.state' --output text aws lightsail get-instance --instance-name "Amazon_Linux-4GB-Virginia-1-swkls4" --query 'instance.state.name' --output text aws lightsail get-instance --instance-name "Amazon_Linux-4GB-Virginia-1-swkls4" --query 'instance.publicIpAddress' --output text aws lightsail get-static-ip --static-ip-name "StaticIp-Virginia-1-swkls4" --query 'staticIp.ipAddress' --output text aws lightsail create-instances --profile "rundeck" --instance-names "swkls-sandbox-nano" --blueprint-id "amazon_linux_2018_03_0_1" --availability-zone "us-east-1a" --bundle-id "nano_2_0"

aws lightsail allocate-static-ip --profile "rundeck" --static-ip-name "swkls-sandbox-ip"

aws lightsail attach-static-ip --profile "rundeck" --static-ip-name "swkls-sandbox-ip" --instance-name "swkls-sandbox-nano"

aws lightsail reboot-instance --profile "rundeck" --instance-name "swkls-sandbox-nano"

aws lightsail get-static-ip --profile "rundeck" --static-ip-name "swkls-sandbox-ip"

aws lightsail open-instance-public-ports --profile "rundeck" --instance-name "swkls-sandbox-nano" --port-info fromPort=443,protocol=TCP,toPort=443

BASH example for testing state and waiting til running: while STATE=$(aws lightsail get-instance --instance-name "Amazon_Linux-4GB-Virginia-1-swkls4" --query 'instance.state.name' --output text); test "$STATE" != "running"; do

   sleep 30;

done;