awscurl Documentation

repository·master·Indexed 21 days ago

https://github.com/okigan/awscurl

A curl-like command-line tool that automates AWS Signature Version 4 request signing for authenticated requests to AWS services. Supports installation via pip, Homebrew, and Docker, with features for credential resolution from ~/.aws/credentials and environment variables.

Tokens
1.8K
Snippets
5
Records
5
Agent score
25%

What's inside awscurl

  1. Run awscurl via Docker

    master

    You can run awscurl using Docker without installing it on your host system.

    Pull the image

    docker pull okigan/awscurl
    # or
    docker pull ghcr.io/okigan/awscurl

    Basic execution

    Pass credentials directly via flags:

    docker run --rm -it okigan/awscurl --access_key ACCESS_KEY --secret_key SECRET_KEY --service s3 s3://...

    Using local AWS credentials

    Mount your local ~/.aws directory to the container to use your existing profiles:

    docker run --rm -it -v "$HOME/.aws:/root/.aws" okigan/awscurl --service s3 s3://...

    To use awscurl as if it were installed locally, add this alias to your shell configuration:

    alias awscurl='docker run --rm -ti -v "$HOME/.aws:/root/.aws" -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -e AWS_SECURITY_TOKEN -e AWS_PROFILE okigan/awscurl'
  2. Install awscurl

    master

    You can install awscurl using several methods depending on your environment:

    pip install awscurl

    From source (Bleeding edge)

    pip install git+https://github.com/okigan/awscurl

    Via Homebrew (macOS)

    brew install awscurl
  3. Build and run awscurl using Docker

    master

    You can build a Docker image for awscurl and run it in a container. To ensure the container can access your AWS credentials, you should mount your local AWS configuration directory and pass through your environment variables.

    Build the image

    docker build -t awscurl .

    Run the container with AWS credentials

    Use the following command to run awscurl while mapping your local ~/.aws directory to the container's root user directory and passing through necessary AWS environment variables:

    docker run --rm -ti -v "$HOME/.aws:/root/.aws" -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -e AWS_SECURITY_TOKEN -e AWS_PROFILE -e AWS_REGION awscurl "${api_url_base}/api/rxxxxx"

    Interactive shell access

    To drop into a shell inside the awscurl container for debugging or manual exploration, use:

    docker run -it --entrypoint sh awscurl
    docker build -t awscurl .
    
    docker run --rm -ti -v "$HOME/.aws:/root/.aws" -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -e AWS_SECURITY_TOKEN -e AWS_PROFILE -e AWS_REGION awscurl "${api_url_base}/api/rxxxxx"
  4. Examples of awscurl usage

    master

    List S3 bucket content

    awscurl --service s3 'https://awscurl-sample-bucket.s3.amazonaws.com'

    Call EC2 API

    awscurl --service ec2 'https://ec2.amazonaws.com?Action=DescribeRegions&Version=2013-10-15'

    Call API Gateway with POST data

    awscurl --service execute-api -X POST -d @request.json \
      https://<prefix>.execute-api.us-east-1.amazonaws.com/<resource>
  5. Reference: awscurl CLI options

    master

    The awscurl command-line interface provides options for request signing, authentication, and standard curl-like behavior.

    Precedence Rule: Command-line values override environment variables, which override defaults.

    Credential Resolution: If --access_key or --secret_key (or their corresponding environment variables) are not specified, awscurl attempts to use credentials from ~/.aws/credentials. If no --profile or AWS_PROFILE is specified, it uses the default profile.

    usage: __main__.py [-h] [-v] [-i] [-X REQUEST] [-d DATA] [-H HEADER] [-k] [--fail-with-body] [--data-binary] [--region REGION] [--profile PROFILE] [--service SERVICE] 
                       [--access_key ACCESS_KEY] [--secret_key SECRET_KEY] [--security_token SECURITY_TOKEN] [--session_token SESSION_TOKEN] [-L] [-o <file>] 
                       uri
    
    positional arguments:
      uri
    
    options:
      -h, --help            show this help message and exit
      -v, --verbose         verbose flag (default: False)
      -i, --include         include headers in the output (default: False)
      -X REQUEST, --request REQUEST
                            Specify request command to use (default: GET)
      -d DATA, --data DATA  HTTP POST data (default: )
      -H HEADER, --header HEADER
                            HTTP header (default: None)
      -k, --insecure        Allow insecure server connections when using SSL (default: False)
      --fail-with-body      Fail on HTTP errors but save the body (default: False)
      --data-binary         Process HTTP POST data exactly as specified with no extra processing whatsoever. (default: False)
      --region REGION       AWS region [env var: AWS_DEFAULT_REGION] (default: us-east-1)
      --profile PROFILE     AWS profile [env var: AWS_PROFILE] (default: default)
      --service SERVICE     AWS service (default: execute-api)
      --access_key ACCESS_KEY
                            [env var: AWS_ACCESS_KEY_ID] (default: None)
      --secret_key SECRET_KEY
                            [env var: AWS_SECRET_ACCESS_KEY] (default: None)
      --security_token SECURITY_TOKEN
                            [env var: AWS_SECURITY_TOKEN] (default: None)
      --session_token SESSION_TOKEN
                            [env var: AWS_SESSION_TOKEN] (default: None)
      -L, --location        Follow redirects (default: False)
      -o <file>, --output <file>
                            Write to file instead of stdout (default: )