Skip to main content

Set AWS envars from `aws configure`, then run a command.

Project description

Set AWS environment variables from the configuration files maintained by aws configure, then run a command.

Installation

  • pip install with_aws_config

  • pip show with-aws-config -f

  • Ensure with-aws-config is on your PATH

Usage

with-aws-config [-h] [--verbose] [--profile PROFILE] COMMAND [ARGUMENT ...]

Positional arguments

COMMAND

the command to run, e.g. ec2-describe-instances, aws, or ansible

ARGUMENT

the command’s arguments, e.g. iam get-user

If any arguments are options, specify -- before the command to end with-aws-config’s optional argument parsing.

Optional arguments

-h, --help

show this help message and exit

--verbose, -v

output debugging information to stderr

--profile PROFILE, -p PROFILE

set the profile, ignoring any environment variables

Behaviour

with-aws-config:

You have three ways to specify the profile:

Examples

Run a command:

with-aws-config -- aws iam get-user
with-aws-config -- ec2-list-instances
with-aws-config -- ansible-playbook setup-vpc.yaml

Specify a profile as an option:

with-aws-config --profile=default -- ec2-describe-instances

Specify a profile via the environment:

env AWS_DEFAULT_PROFILE=default with-aws-config -- ec2-describe-instances

Note we’ve used -- in each to force the end of the optional arguments.

Environment Variables

Input

  • AWS_PROFILE is used to specify profile if --profile is not given

  • AWS_DEFAULT_PROFILE is used if AWS_PROFILE is not set

  • HOME is required to locate $HOME/.aws

Output

COMMAND will be run with the environment supplied to with-aws-config, with the following exceptions:

The following environment variables will be removed:

  • AWS_CONFIG_FILE

  • AWS_DEFAULT_PROFILE

  • AWS_PROFILE

  • AWS_SESSION_TOKEN

The following environment variables will be set based on the AWS profile:

  • AWS_ACCESS_KEY

  • AWS_ACCESS_KEY_ID

  • AWS_DEFAULT_REGION

  • AWS_SECRET_ACCESS_KEY

  • AWS_SECRET_KEY

  • EC2_URL

AWS_DEFAULT_REGION and EC2_URL will default to point to us-west-2 if not configured during aws configure.

Why this many?

  • aws, boto, and ansible need AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_DEFAULT_REGION

  • ec2-* need AWS_ACCESS_KEY, AWS_SECRET_KEY, and EC2_URL

Exit Status

with-aws-config exits with either:

  • The exit status of COMMAND or, if it can’t be run:

  • One of the following status codes indicating why:

    124:

    no configuration files found

    125:

    no configuration section found for the requested profile

    127:

    command not found

    130:

    interrupted by user with ^C

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

with_aws_config-1.0.4.tar.gz (5.1 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page