LinuxCommandLibrary

aws-s3api

Call low-level Amazon S3 API operations

TLDR

Create bucket in a specific region

$ aws s3api create-bucket --bucket [bucket_name] --region [region] --create-bucket-configuration LocationConstraint=[region]
copy

Delete a bucket
$ aws s3api delete-bucket --bucket [bucket_name]
copy

List buckets
$ aws s3api list-buckets
copy

List the objects inside of a bucket and only show each object's key and size
$ aws s3api list-objects --bucket [bucket_name] --query '[Contents[].{Key: Key, Size: Size]}'
copy

Add an object to a bucket
$ aws s3api put-object --bucket [bucket_name] --key [object_key] --body [path/to/file]
copy

Download object from a bucket (The output file is always the last argument)
$ aws s3api get-object --bucket [bucket_name] --key [object_key] [path/to/output_file]
copy

Apply an Amazon S3 bucket policy to a specified bucket
$ aws s3api put-bucket-policy --bucket [bucket_name] --policy file://[path/to/bucket_policy.json]
copy

Download the Amazon S3 bucket policy from a specified bucket
$ aws s3api get-bucket-policy --bucket [bucket_name] --query Policy --output [json|table|text|yaml|yaml-stream] > [path/to/bucket_policy]
copy

SYNOPSIS

aws s3api operation [operation-parameters] [--generate-cli-skeleton (0|1|2)] [--cli-input-json file] [--cli-binary-format (raw-in-base64-out|raw-in-raw-out|base64-in-base64-out)]

PARAMETERS

--cli-input-json
    Perform operation using JSON string from file or stdin.

--generate-cli-skeleton
    Print JSON skeleton (0=empty, 1=basic, 2=full) for operation parameters.

--cli-binary-format
    Specify binary input/output format for blobs (raw-in-base64-out, etc.).

--debug (-d)
    Enable debug logging.

--endpoint-url
    Override default endpoint URL.

--no-verify-ssl
    Disable SSL certificate verification.

--cli-read-timeout
    Max seconds to wait for response read.

--cli-connect-timeout
    Max seconds to wait for connection.

--profile
    Use specific profile from credentials file.

--region
    AWS region (e.g., us-east-1).

--output (json|text|table)
    Output format.

--query
    JMESPath query to filter output.

--no-cli-pager
    Disable cli pager for output.

--help (-h)
    Show help for command.

DESCRIPTION

aws s3api is a subcommand of the AWS Command Line Interface (CLI) that provides direct, low-level access to Amazon Simple Storage Service (S3) APIs. Unlike the high-level aws s3 commands designed for simplified file transfers and management, aws s3api maps one-to-one with S3 REST API operations, offering precise control over features like multipart uploads, object tagging, ACLs, versioning, encryption, replication, and inventory configurations.

Users invoke specific operations such as put-object, get-object, list-objects-v2, or create-bucket, supplying parameters like --bucket, --key, and others required by the API. It supports JSON input via --cli-input-json for complex payloads and --generate-cli-skeleton for generating parameter templates, making it ideal for scripting and automation.

Requires AWS CLI v1 or v2 installed, valid credentials configured (via aws configure), and appropriate IAM permissions. Outputs in JSON by default but customizable. Best for advanced users familiar with S3 APIs; beginners should start with aws s3.

CAVEATS

Parameters vary by operation; use aws s3api help for specifics. Requires exact API parameter names/casing. Large JSON inputs may hit CLI limits. Not suited for bulk transfers (use aws s3 or aws s3 sync). IAM permissions must match API calls.

COMMON SUBCOMMANDS

put-object, get-object, delete-object, list-objects-v2, create-bucket, head-object, copy-object, complete-multipart-upload, list-buckets (full list via aws s3api help).

EXAMPLE

aws s3api put-object --bucket mybucket --key file.txt --body ./local.txt
aws s3api list-objects-v2 --bucket mybucket --query 'Contents[].{Key:Key,Size:Size}'

HISTORY

Introduced in AWS CLI v1.7.0 (2014) for direct S3 API access. Improved in v2 (2020+) with faster performance, better binary handling, and enhanced JSON support. Widely used in DevOps for custom S3 integrations.

SEE ALSO

aws(1), aws-s3(1), s3cmd(1)

Copied to clipboard