awscli-local (awslocal)

repository·master·Indexed 23 days ago

https://github.com/localstack/awscli-local

A thin wrapper around the AWS CLI that automatically directs commands to a LocalStack instance, removing the need to manually specify endpoint URLs. It supports standard AWS CLI subcommands and flags, provides configuration via environment variables like AWS_ENDPOINT_URL, and includes specific compatibility guidance for CloudFormation and S3 addressing styles.

Tokens
1.2K
Snippets
5
Records
10
Agent score
80%

What's inside awscli-local

  1. Configure command completion for awslocal

    master

    Since awslocal is compatible with the aws CLI completion feature, you can enable tab-completion for your shell.

    For Bash: Add the following lines to your ~/.bashrc to register completion for both aws and awslocal:

    complete -C '/usr/local/bin/aws_completer' aws
    complete -C '/usr/local/bin/aws_completer' awslocal

    For other shells: Follow the official AWS CLI guide for your specific shell and ensure you register the completion for awslocal as well.

  2. Install the awslocal CLI

    master

    The awslocal command is a thin wrapper around the aws CLI designed for use with LocalStack. You can install it via pip.

    To install awslocal along with the latest AWS CLI version 1 (awscli), use:

    pip install awscli-local[ver1]

    If you are on macOS or using ZSH, use quotes around the package name:

    pip install "awscli-local[ver1]"

    If you already manage your own version of the AWS CLI (v1 or v2) and only want to install the awslocal wrapper script, use:

    pip install awscli-local
  3. Configure awslocal via environment variables

    master

    You can control how awslocal connects to LocalStack using the following environment variables:

    • AWS_ENDPOINT_URL: The endpoint URL to connect to. This takes precedence over LOCALSTACK_HOST and USE_SSL.
    • LOCALSTACK_HOST (deprecated): A <hostname>:<port> variable defining the LocalStack location (defaults to localhost:4566).
    • USE_SSL (deprecated): A boolean indicating whether to use SSL when connecting (defaults to False).
  4. Use awslocal to interact with LocalStack

    master

    The awslocal CLI is a thin wrapper around the standard AWS CLI (aws). It simplifies interacting with LocalStack by automatically injecting the correct --endpoint-url for the service you are calling, so you don't have to specify it manually for every command.

    Instead of running: aws --endpoint-url=https://localhost:4568 --no-verify-ssl kinesis list-streams

    You can simply run: awslocal kinesis list-streams

    awslocal kinesis list-streams
  5. CloudFormation package and deploy with awslocal

    master

    When using CloudFormation package or deploy commands, awslocal attempts to ensure that S3 artifacts are also directed to the LocalStack endpoint.

    Important Compatibility Note: If you are using AWS CLI v2, awslocal currently has limitations with the cloudformation package/deploy commands. If you encounter issues, it is recommended to install and use AWS CLI v1 via pip install awscli to ensure full compatibility with awslocal's patching mechanism.

  6. Workaround for CloudFormation package limitations with AWS CLI v2

    master

    There is a known limitation when using the cloudformation package ... command with AWS CLI v2: it is currently impossible to specify the S3 endpoint URL.

    To resolve this, you have two options:

    1. Recommended: Downgrade to the v1 AWS CLI.
    2. Advanced (Not recommended): Install AWS CLI v2 from sources within a Python virtualenv to avoid system conflicts:
    virtualenv .venv
    . .venv/bin/activate
    pip install https://github.com/boto/botocore/archive/v2.zip https://github.com/aws/aws-cli/archive/v2.zip
  7. Use awslocal to simplify LocalStack commands

    master

    The awslocal command has the same usage as the standard aws CLI. It eliminates the need to manually specify the --endpoint-url for every command by automatically pointing requests to the LocalStack endpoint.

    Example: Instead of specifying the endpoint manually:

    aws --endpoint-url=http://localhost:4566 kinesis list-streams

    You can simply run:

    awslocal kinesis list-streams
  8. S3 Addressing Style requirement for awslocal

    master
    If you are using S3 with a virtual addressing style, awslocal may issue a warning. For optimal compatibility with LocalStack via awslocal, ensure your AWS configuration for S3 is set to path addressing style rather than virtual or auto.
  9. awslocal CLI usage and options

    master

    The awslocal command follows the same subcommand structure as the AWS CLI. You can pass any standard AWS CLI subcommand or flag to awslocal.

    To see the full help documentation for the underlying AWS CLI subcommands, run: awslocal aws help

    Note: awslocal automatically handles endpoint injection for most services. However, for certain services like help or configure, it defaults to standard behavior without injecting a LocalStack endpoint.

  10. Run awslocal on Windows

    master
    On Windows systems, the awslocal command is executed via the awslocal.bat batch script. This script acts as a wrapper that invokes the underlying awslocal Python module using the system's Python interpreter. You can pass all standard AWS CLI arguments and flags directly to the batch script.