### Install awscurl from source Source: https://github.com/okigan/awscurl/blob/master/README.md Install the latest development version directly from the GitHub repository. ```sh pip install git+https://github.com/okigan/awscurl ``` -------------------------------- ### Install awscurl via pip Source: https://github.com/okigan/awscurl/blob/master/README.md Standard installation method using pip. ```sh pip install awscurl ``` -------------------------------- ### Install awscurl via Homebrew Source: https://github.com/okigan/awscurl/blob/master/README.md Installation method for macOS users. ```sh brew install awscurl ``` -------------------------------- ### awscurl Command-Line Examples Source: https://context7.com/okigan/awscurl/llms.txt Examples of using awscurl for various AWS services and operations. ```APIDOC ## Multiple custom headers for DynamoDB ```bash awscurl --service dynamodb --region us-east-1 \ -X POST \ -H 'Content-Type: application/x-amz-json-1.0' \ -H 'X-Amz-Target: DynamoDB_20120810.GetItem' \ -d '{ "TableName": "Users", "Key": {"userId": {"S": "user123"}} }' \ 'https://dynamodb.us-east-1.amazonaws.com' ``` ## Custom headers for Lambda invocation ```bash awscurl --service lambda --region us-east-1 \ -X POST \ -H 'Content-Type: application/json' \ -H 'X-Amz-Invocation-Type: RequestResponse' \ -d '{"key": "value"}' \ 'https://lambda.us-east-1.amazonaws.com/2015-03-31/functions/my-function/invocations' ``` ## Output Options ### Include response headers in output ```bash awscurl --service s3 -i 'https://my-bucket.s3.amazonaws.com' ``` ### Verbose mode for debugging (shows signing details) ```bash awscurl --service s3 -v 'https://my-bucket.s3.amazonaws.com' ``` ### Write response to file ```bash awscurl --service s3 -o response.xml 'https://my-bucket.s3.amazonaws.com' ``` ### Binary data output (for downloading files) ```bash awscurl --service s3 --data-binary -o myfile.zip \ 'https://my-bucket.s3.amazonaws.com/myfile.zip' ``` ### Fail on HTTP errors but still save response body ```bash awscurl --service s3 --fail-with-body 'https://my-bucket.s3.amazonaws.com/missing' ``` ## SSL and Redirect Options ### Skip SSL verification (for self-signed certificates) ```bash awscurl --service execute-api -k \ 'https://internal-api.example.com/resource' ``` ### Follow redirects automatically ```bash awscurl --service s3 -L \ 'https://my-bucket.s3.amazonaws.com/redirect-object' ``` ## Docker Usage ### Run with explicit credentials ```bash docker run --rm okigan/awscurl \ --access_key AKIAIOSFODNN7EXAMPLE \ --secret_key wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY \ --service s3 \ 'https://my-bucket.s3.amazonaws.com' ``` ### Run with mounted AWS credentials file ```bash docker run --rm -v "$HOME/.aws:/root/.aws" okigan/awscurl \ --service s3 \ 'https://my-bucket.s3.amazonaws.com' ``` ### Run with environment variables ```bash docker run --rm \ -e AWS_ACCESS_KEY_ID \ -e AWS_SECRET_ACCESS_KEY \ -e AWS_DEFAULT_REGION \ okigan/awscurl \ --service s3 \ 'https://my-bucket.s3.amazonaws.com' ``` ### Create shell alias for convenience ```bash 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' ``` ``` -------------------------------- ### Perform Basic GET Request Source: https://context7.com/okigan/awscurl/llms.txt Execute a simple GET request to an AWS service endpoint with automatic signature signing. ```bash # List contents of an S3 bucket awscurl --service s3 'https://my-bucket.s3.amazonaws.com' ``` -------------------------------- ### List S3 bucket content Source: https://github.com/okigan/awscurl/blob/master/README.md Example of listing objects in an S3 bucket using awscurl. ```sh $ awscurl --service s3 'https://awscurl-sample-bucket.s3.amazonaws.com' | tidy -xml -iq ``` -------------------------------- ### Describe EC2 regions Source: https://github.com/okigan/awscurl/blob/master/README.md Example of querying EC2 regions using the AWS API. ```sh $ awscurl --service ec2 'https://ec2.amazonaws.com?Action=DescribeRegions&Version=2013-10-15' | tidy -xml -iq ``` -------------------------------- ### Programmatic CLI Execution with inner_main Source: https://context7.com/okigan/awscurl/llms.txt Allows programmatic execution of awscurl's CLI functionality, useful for testing and integration. Supports GET and POST requests with various options. ```python from awscurl.awscurl import inner_main # Run awscurl programmatically with CLI arguments exit_code = inner_main([ '--service', 's3', '--region', 'us-east-1', '--access_key', 'AKIAIOSFODNN7EXAMPLE', '--secret_key', 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY', 'https://my-bucket.s3.amazonaws.com' ]) print(f"Exit code: {exit_code}") # 0 for success, 22 for HTTP errors with --fail-with-body ``` ```python # POST request with data exit_code = inner_main([ '--service', 'execute-api', '-X', 'POST', '-d', '{"key": "value"}', '-H', 'Content-Type: application/json', 'https://abc123.execute-api.us-east-1.amazonaws.com/prod/resource' ]) ``` -------------------------------- ### Call API Gateway Source: https://github.com/okigan/awscurl/blob/master/README.md Example of sending a POST request to an API Gateway endpoint with a JSON payload. ```sh $ awscurl --service execute-api -X POST -d @request.json \ https://.execute-api.us-east-1.amazonaws.com/ ``` -------------------------------- ### Configure Authentication Methods Source: https://context7.com/okigan/awscurl/llms.txt Authenticate using explicit credentials, environment variables, named profiles, or session tokens. ```bash # Using explicit credentials awscurl --service s3 \ --access_key AKIAIOSFODNN7EXAMPLE \ --secret_key wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY \ 'https://my-bucket.s3.amazonaws.com' # Using environment variables export AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE export AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY export AWS_DEFAULT_REGION=us-east-1 awscurl --service s3 'https://my-bucket.s3.amazonaws.com' # Using a named AWS profile from ~/.aws/credentials awscurl --service s3 --profile production 'https://my-bucket.s3.amazonaws.com' # Using session tokens (for temporary credentials/assumed roles) awscurl --service s3 \ --access_key ASIAIOSFODNN7EXAMPLE \ --secret_key wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY \ --session_token FwoGZXIvYXdzEBYaD... \ 'https://my-bucket.s3.amazonaws.com' ``` -------------------------------- ### Configure SSL and Redirects Source: https://context7.com/okigan/awscurl/llms.txt Manage SSL verification and automatic redirect following. ```bash awscurl --service execute-api -k \ 'https://internal-api.example.com/resource' ``` ```bash awscurl --service s3 -L \ 'https://my-bucket.s3.amazonaws.com/redirect-object' ``` -------------------------------- ### Execute awscurl via alias Source: https://github.com/okigan/awscurl/blob/master/README.md Run the tool after setting up the Docker alias. ```sh awscurl ``` -------------------------------- ### Build and Run awscurl Docker Image Source: https://github.com/okigan/awscurl/blob/master/DEVELOP.md Commands to build the image and run it with AWS environment variables or an interactive shell. ```sh 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" docker run -it --entrypoint sh awscurl ``` -------------------------------- ### Execute AWS Service Requests via CLI Source: https://context7.com/okigan/awscurl/llms.txt Use custom headers and methods to interact with AWS services like DynamoDB and Lambda. ```bash awscurl --service dynamodb --region us-east-1 \ -X POST \ -H 'Content-Type: application/x-amz-json-1.0' \ -H 'X-Amz-Target: DynamoDB_20120810.GetItem' \ -d '{ "TableName": "Users", "Key": {"userId": {"S": "user123"}} }' \ 'https://dynamodb.us-east-1.amazonaws.com' ``` ```bash awscurl --service lambda --region us-east-1 \ -X POST \ -H 'Content-Type: application/json' \ -H 'X-Amz-Invocation-Type: RequestResponse' \ -d '{"key": "value"}' \ 'https://lambda.us-east-1.amazonaws.com/2015-03-31/functions/my-function/invocations' ``` -------------------------------- ### Configure CLI Output and Behavior Source: https://context7.com/okigan/awscurl/llms.txt Control output formatting, debugging, file saving, and error handling for CLI requests. ```bash awscurl --service s3 -i 'https://my-bucket.s3.amazonaws.com' ``` ```bash awscurl --service s3 -v 'https://my-bucket.s3.amazonaws.com' ``` ```bash awscurl --service s3 -o response.xml 'https://my-bucket.s3.amazonaws.com' ``` ```bash awscurl --service s3 --data-binary -o myfile.zip \ 'https://my-bucket.s3.amazonaws.com/myfile.zip' ``` ```bash awscurl --service s3 --fail-with-body 'https://my-bucket.s3.amazonaws.com/missing' ``` -------------------------------- ### awscurl Command-Line Options Source: https://github.com/okigan/awscurl/blob/master/README.md This section details the various command-line options available for the awscurl tool, including request methods, data, headers, region, authentication, and output formatting. ```APIDOC ## awscurl Command-Line Usage ### Description `awscurl` is a command-line tool that mimics the functionality of `curl` but adds AWS request signing capabilities. It allows users to interact with AWS services by constructing and signing HTTP requests. ### Method This documentation describes the command-line interface and its options, not a specific HTTP method for an endpoint. ### Endpoint Not applicable, as this describes the tool's general usage and options. ### Options `awscurl` accepts the following 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. (default: us-east-1) [env var: AWS_DEFAULT_REGION] - `--profile PROFILE`: AWS profile. (default: default) [env var: AWS_PROFILE] - `--service SERVICE`: AWS service. (default: execute-api) - `--access_key ACCESS_KEY`: AWS access key ID. (default: None) [env var: AWS_ACCESS_KEY_ID] - `--secret_key SECRET_KEY`: AWS secret access key. (default: None) [env var: AWS_SECRET_ACCESS_KEY] - `--security_token SECURITY_TOKEN`: AWS security token. (default: None) [env var: AWS_SECURITY_TOKEN] - `--session_token SESSION_TOKEN`: AWS session token. (default: None) [env var: AWS_SESSION_TOKEN] - `-L, --location`: Follow redirects. (default: False) - `-o , --output `: Write to file instead of stdout. (default: ) ### Positional Arguments - `uri`: The URI to which the request will be made. ### Authentication - If `--access_key` or `--secret_key` (or their environment variables) are not specified, `awscurl` attempts to use credentials from `~/.aws/credentials`. - If `--profile` or `AWS_PROFILE` is not specified, `awscurl` uses the `default` profile. ### Example Usage ```sh awscurl --region us-west-2 --service s3 https://my-bucket.s3.amazonaws.com/my-object ``` This command would make a GET request to the specified S3 object in the `us-west-2` region, with automatic signing. ``` -------------------------------- ### Load AWS Configuration in Python Source: https://context7.com/okigan/awscurl/llms.txt Retrieve credentials from local files or profiles using load_aws_config. ```python from awscurl.awscurl import load_aws_config # Load credentials from default profile access_key, secret_key, session_token = load_aws_config( access_key=None, secret_key=None, security_token=None, credentials_path='/home/user/.aws/credentials', profile='default' ) print(f"Access Key: {access_key[:4]}***") print(f"Secret Key: {secret_key[:4]}***") # Load from a named profile access_key, secret_key, session_token = load_aws_config( access_key=None, secret_key=None, security_token=None, credentials_path='/home/user/.aws/credentials', profile='production' ) # Override with explicit credentials (partial) access_key, secret_key, session_token = load_aws_config( access_key='AKIAIOSFODNN7EXAMPLE', # Use this access key secret_key=None, # Load from credentials file security_token=None, credentials_path='/home/user/.aws/credentials', profile='default' ) ``` -------------------------------- ### Query EC2 API Source: https://context7.com/okigan/awscurl/llms.txt Retrieve instance and region information using the EC2 service API. ```bash # Describe all AWS regions awscurl --service ec2 \ 'https://ec2.amazonaws.com?Action=DescribeRegions&Version=2013-10-15' # Describe instances in a specific region awscurl --service ec2 --region us-west-2 \ 'https://ec2.us-west-2.amazonaws.com?Action=DescribeInstances&Version=2016-11-15' ``` -------------------------------- ### Make Programmatic Requests with Python Source: https://context7.com/okigan/awscurl/llms.txt Use the make_request function to perform signed HTTP operations from Python. ```python from awscurl.awscurl import make_request # Make a GET request to S3 response = make_request( method='GET', service='s3', region='us-east-1', uri='https://my-bucket.s3.amazonaws.com', headers={'Accept': 'application/xml'}, data='', access_key='AKIAIOSFODNN7EXAMPLE', secret_key='wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY', security_token=None, data_binary=False, verify=True, allow_redirects=False ) print(f"Status: {response.status_code}") print(f"Body: {response.text}") # Make a POST request to API Gateway response = make_request( method='POST', service='execute-api', region='us-east-1', uri='https://abc123.execute-api.us-east-1.amazonaws.com/prod/users', headers={'Content-Type': 'application/json'}, data='{"name": "John", "email": "john@example.com"}', access_key='AKIAIOSFODNN7EXAMPLE', secret_key='wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY', security_token=None, data_binary=False, verify=True, allow_redirects=False ) if response.ok: print(f"Success: {response.json()}") else: print(f"Error: {response.status_code}") ``` -------------------------------- ### Configure AWS Regions Source: https://context7.com/okigan/awscurl/llms.txt Specify target regions for signing, including support for multi-region SigV4a requests. ```bash # Specify region explicitly awscurl --service dynamodb --region eu-west-1 \ -X POST \ -H 'Content-Type: application/x-amz-json-1.0' \ -H 'X-Amz-Target: DynamoDB_20120810.ListTables' \ -d '{"Limit": 10}' \ 'https://dynamodb.eu-west-1.amazonaws.com' # Use SigV4a for multi-region requests (region="*") awscurl --service s3 --region '*' \ 'https://my-multi-region-bucket.s3.amazonaws.com' ``` -------------------------------- ### Create awscurl Docker alias Source: https://github.com/okigan/awscurl/blob/master/README.md Define a shell alias to simplify running awscurl commands through Docker. ```sh 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' ``` -------------------------------- ### Run awscurl via Docker Source: https://github.com/okigan/awscurl/blob/master/README.md Execute awscurl commands using a Docker container, with options for manual credentials or mounting local AWS configuration. ```sh $ docker run --rm -it okigan/awscurl --access_key ACCESS_KEY --secret_key SECRET_KEY --service s3 s3://... # or allow access to local credentials as following $ docker run --rm -it -v "$HOME/.aws:/root/.aws" okigan/awscurl --service s3 s3://... ``` -------------------------------- ### Python API Reference Source: https://context7.com/okigan/awscurl/llms.txt Reference for the Python functions provided by the awscurl library. ```APIDOC ## make_request Function The core function for making signed HTTP requests to AWS services programmatically from Python code. ```python from awscurl.awscurl import make_request # Make a GET request to S3 response = make_request( method='GET', service='s3', region='us-east-1', uri='https://my-bucket.s3.amazonaws.com', headers={'Accept': 'application/xml'}, data='', access_key='AKIAIOSFODNN7EXAMPLE', secret_key='wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY', security_token=None, data_binary=False, verify=True, allow_redirects=False ) print(f"Status: {response.status_code}") print(f"Body: {response.text}") # Make a POST request to API Gateway response = make_request( method='POST', service='execute-api', region='us-east-1', uri='https://abc123.execute-api.us-east-1.amazonaws.com/prod/users', headers={'Content-Type': 'application/json'}, data='{"name": "John", "email": "john@example.com"}', access_key='AKIAIOSFODNN7EXAMPLE', secret_key='wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY', security_token=None, data_binary=False, verify=True, allow_redirects=False ) if response.ok: print(f"Success: {response.json()}") else: print(f"Error: {response.status_code}") ``` ## load_aws_config Function Load AWS credentials from the credentials file or botocore session, supporting multiple profiles. ```python from awscurl.awscurl import load_aws_config # Load credentials from default profile access_key, secret_key, session_token = load_aws_config( access_key=None, secret_key=None, security_token=None, credentials_path='/home/user/.aws/credentials', profile='default' ) print(f"Access Key: {access_key[:4]}***") print(f"Secret Key: {secret_key[:4]}***") # Load from a named profile access_key, secret_key, session_token = load_aws_config( access_key=None, secret_key=None, security_token=None, credentials_path='/home/user/.aws/credentials', profile='production' ) # Override with explicit credentials (partial) access_key, secret_key, session_token = load_aws_config( access_key='AKIAIOSFODNN7EXAMPLE', # Use this access key secret_key=None, # Load from credentials file security_token=None, credentials_path='/home/user/.aws/credentials', profile='default' ) ``` ``` -------------------------------- ### Run awscurl in Docker Source: https://context7.com/okigan/awscurl/llms.txt Execute awscurl within a container using explicit credentials, mounted volumes, or environment variables. ```bash docker run --rm okigan/awscurl \ --access_key AKIAIOSFODNN7EXAMPLE \ --secret_key wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY \ --service s3 \ 'https://my-bucket.s3.amazonaws.com' ``` ```bash docker run --rm -v "$HOME/.aws:/root/.aws" okigan/awscurl \ --service s3 \ 'https://my-bucket.s3.amazonaws.com' ``` ```bash docker run --rm \ -e AWS_ACCESS_KEY_ID \ -e AWS_SECRET_ACCESS_KEY \ -e AWS_DEFAULT_REGION \ okigan/awscurl \ --service s3 \ 'https://my-bucket.s3.amazonaws.com' ``` ```bash 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' ``` -------------------------------- ### Send POST Requests with JSON Data Source: https://context7.com/okigan/awscurl/llms.txt Send POST requests with JSON payloads, supporting direct strings, files, or stdin input. ```bash # POST request to API Gateway endpoint awscurl --service execute-api \ -X POST \ -H 'Content-Type: application/json' \ -d '{"name": "John", "email": "john@example.com"}' \ 'https://abc123.execute-api.us-east-1.amazonaws.com/prod/users' # POST with data from file awscurl --service execute-api \ -X POST \ -d @request.json \ 'https://abc123.execute-api.us-east-1.amazonaws.com/prod/resource' # POST with data from stdin echo '{"action": "process"}' | awscurl --service execute-api \ -X POST \ -d @- \ 'https://abc123.execute-api.us-east-1.amazonaws.com/prod/process' ``` -------------------------------- ### Parse URL Path to Dictionary Source: https://context7.com/okigan/awscurl/llms.txt Parses a URL into its component parts, useful for request signing. Handles S3 URLs and URLs with custom ports. ```python from awscurl.awscurl import url_path_to_dict # Parse an S3 URL url_dict = url_path_to_dict('https://my-bucket.s3.amazonaws.com/path/to/object?param=value') print(url_dict) # Output: # { # 'schema': 'https', # 'user': None, # 'password': None, # 'host': 'my-bucket.s3.amazonaws.com', # 'port': None, # 'path': '/path/to/object', # 'query': 'param=value' # } ``` ```python # Parse URL with port url_dict = url_path_to_dict('http://localhost:4566/my-bucket') print(f"Host: {url_dict['host']}, Port: {url_dict['port']}, Path: {url_dict['path']}") # Output: Host: localhost, Port: 4566, Path: /my-bucket ``` -------------------------------- ### Pull awscurl Docker image Source: https://github.com/okigan/awscurl/blob/master/README.md Retrieve the official awscurl image from Docker Hub or GitHub Container Registry. ```sh docker pull okigan/awscurl # or via docker pull ghcr.io/okigan/awscurl ``` ```sh docker pull ghcr.io/okigan/awscurl ``` -------------------------------- ### SHA-256 Hashing and HMAC Signing Source: https://context7.com/okigan/awscurl/llms.txt Provides utility functions for SHA-256 hashing of text and binary data, and HMAC signing for key derivation. Used in AWS Signature Version 4. ```python from awscurl.utils import sha256_hash, sha256_hash_for_binary_data, sign # Hash text data text_hash = sha256_hash('Hello, World!') print(f"Text hash: {text_hash}") # Output: Text hash: dffd6021bb2bd5b0af676290809ec3a53191dd81c7f70a4b28688a362182986f ``` ```python # Hash binary data binary_data = b'\x00\x01\x02\x03' binary_hash = sha256_hash_for_binary_data(binary_data) print(f"Binary hash: {binary_hash}") ``` ```python # HMAC signing for key derivation key = b'secret-key' message = '20240115' signed = sign(key, message) print(f"Signed (hex): {signed.hex()}") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.