amazon.cloud.s3_bucket module – Create and manage S3 buckets
Note
This module is part of the amazon.cloud collection (version 0.4.0).
It is not included in ansible-core
.
To check whether it is installed, run ansible-galaxy collection list
.
To install it, use: ansible-galaxy collection install amazon.cloud
.
You need further requirements to be able to use this module,
see Requirements for details.
To use it in a playbook, specify: amazon.cloud.s3_bucket
.
New in amazon.cloud 0.1.0
Synopsis
Create and manage S3 buckets.
Requirements
The below requirements are needed on the host that executes this module.
python >= 3.9
boto3 >= 1.25.0
botocore >= 1.28.0
jsonpatch
Parameters
Parameter |
Comments |
---|---|
Configuration for the transfer acceleration state. |
|
Configures the transfer acceleration state for an Amazon S3 bucket. Choices:
|
|
A canned access control list (ACL) that grants predefined permissions to the bucket. Choices:
|
|
AWS access key ID. See the AWS documentation for more information about access tokens https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys. The The aws_access_key and profile options are mutually exclusive. The aws_access_key_id alias was added in release 5.1.0 for consistency with the AWS botocore SDK. The ec2_access_key alias has been deprecated and will be removed in a release after 2024-12-01. Support for the |
|
Specifies the configuration and any analyses for the analytics filter of an Amazon S3 bucket. |
|
The ID that identifies the analytics configuration. |
|
The prefix that an object must have to be included in the analytics results. |
|
Specifies data related to access patterns to be collected and made available to analyze the tradeoffs between different storage classes for an Amazon S3 bucket. |
|
Specifies how data related to the storage class analysis for an Amazon S3 bucket should be exported. |
|
Specifies information about where to publish analysis or configuration results for an Amazon S3 bucket and S3 Replication Time Control (S3 RTC). |
|
The account ID that owns the destination S3 bucket. |
|
The Amazon Resource Name (ARN) of the bucket to which data is exported. |
|
Specifies the file format used when exporting data to Amazon S3. Choices:
|
|
The prefix to use when exporting data. The prefix is prepended to all results. |
|
The version of the output schema to use when exporting data. Default: |
|
Tags to use to identify a subset of objects for an Amazon S3 bucket. |
|
Not Provived. |
|
Not Provived. |
|
The location of a CA Bundle to use when validating SSL certificates. The |
|
A dictionary to modify the botocore configuration. Parameters can be found in the AWS documentation https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html#botocore.config.Config. |
|
Specifies default encryption for a bucket using server-side encryption with either Amazon S3-managed keys (SSE-S3) or AWS KMS-managed keys (SSE-KMS). |
|
Specifies the default server-side encryption configuration. |
|
Specifies whether Amazon S3 should use an S3 Bucket Key with server-side encryption using KMS (SSE-KMS) for new objects in the bucket. Existing objects are not affected. Setting the bucket_key_enabled element to true causes Amazon S3 to use an S3 Bucket Key. By default, S3 Bucket Key is not enabled. Choices:
|
|
Specifies the default server-side encryption to apply to new objects in the bucket. If a PUT Object request doesnt specify any server-side encryption, this default encryption will be applied. |
|
KMSMasterKeyID can only be used when you set the value of sse_algorithm as aws:kms. |
|
Not Provived. Choices:
|
|
A name for the bucket. If you dont specify a name, AWS CloudFormation generates a unique physical ID and uses that ID for the bucket name. |
|
Rules that define cross-origin resource sharing of objects in this bucket. |
|
A set of origins and methods (cross-origin access that you want to allow). You can add up to 100 rules to the configuration. |
|
Headers that are specified in the Access-Control-Request-Headers header. |
|
An HTTP method that you allow the origin to execute. Choices:
|
|
One or more origins you want customers to be able to access the bucket from. |
|
One or more headers in the response that you want customers to be able to access from their applications (for example, from a JavaScript XMLHttpRequest object). |
|
A unique identifier for this rule. |
|
The time in seconds that your browser is to cache the preflight response for the specified resource. |
|
Use a The Choices:
|
|
URL to connect to instead of the default AWS endpoints. While this can be used to connection to other AWS-compatible services the amazon.aws and community.aws collections are only tested against AWS. The The ec2_url and s3_url aliases have been deprecated and will be removed in a release after 2024-12-01. Support for the |
|
Cancel IN_PROGRESS and PENDING resource requestes. Because you can only perform a single operation on a given resource at a time, there might be cases where you need to cancel the current resource operation to make the resource available so that another operation may be performed on it. Choices:
|
|
Specifies the S3 Intelligent-Tiering configuration for an Amazon S3 bucket. |
|
The ID used to identify the S3 Intelligent-Tiering configuration. |
|
An object key name prefix that identifies the subset of objects to which the rule applies. |
|
Specifies the status of the configuration. Choices:
|
|
Tags to use to identify a subset of objects for an Amazon S3 bucket. |
|
Not Provived. |
|
Not Provived. |
|
Specifies a list of S3 Intelligent-Tiering storage class tiers in the configuration. At least one tier must be defined in the list. At most, you can specify two tiers in the list, one for each available access_tier: |
|
S3 Intelligent-Tiering access tier. See Storage class for automatically optimizing frequently and infrequently accessed objects for a list of access tiers in the S3 Intelligent-Tiering storage class. Choices:
|
|
The number of consecutive days of no access after which an object will be eligible to be transitioned to the corresponding tier. The minimum number of days specified for Archive Access tier must be at least 90 days and Deep Archive Access tier must be at least 180 days. The maximum can be up to 2 years (730 days). |
|
The inventory configuration for an Amazon S3 bucket. |
|
Specifies information about where to publish analysis or configuration results for an Amazon S3 bucket and S3 Replication Time Control (S3 RTC). |
|
The account ID that owns the destination S3 bucket. |
|
The Amazon Resource Name (ARN) of the bucket to which data is exported. |
|
Specifies the file format used when exporting data to Amazon S3. Choices:
|
|
The prefix to use when exporting data. The prefix is prepended to all results. |
|
Specifies whether the inventory is enabled or disabled. Choices:
|
|
The ID used to identify the inventory configuration. |
|
Object versions to include in the inventory list. Choices:
|
|
Contains the optional fields that are included in the inventory results. Choices:
|
|
The prefix that is prepended to all inventory results. |
|
Specifies the schedule for generating inventory results. Choices:
|
|
Rules that define how Amazon S3 manages objects during their lifetime. |
|
You must specify at least one of the following properties: abort_incomplete_multipart_upload, expiration_date, expiration_in_days, noncurrent_version_expiration_in_days, noncurrent_version_transition, noncurrent_version_transitions, transition, or transitions. |
|
Specifies the days since the initiation of an incomplete multipart upload that Amazon S3 will wait before permanently removing all parts of the upload. |
|
Specifies the number of days after which Amazon S3 aborts an incomplete multipart upload. |
|
The date value in ISO 8601 format. The timezone is always UTC. (YYYY-MM-DDThh:mm:ssZ). |
|
Not Provived. |
|
Not Provived. Choices:
|
|
Not Provived. |
|
Container for the expiration rule that describes when noncurrent objects are expired. If your bucket is versioning-enabled (or versioning is suspended), you can set this action to request that Amazon S3 expire noncurrent object versions at a specific period in the objects lifetime. |
|
Specified the number of newer noncurrent and current versions that must exists before performing the associated action. |
|
Specified the number of days an object is noncurrent before Amazon S3 can perform the associated action. |
|
Not Provived. |
|
Container for the transition rule that describes when noncurrent objects transition to the If your bucket is versioning-enabled (or versioning is suspended), you can set this action to request that Amazon S3 transition noncurrent object versions to the |
|
Specified the number of newer noncurrent and current versions that must exists before performing the associated action. |
|
The class of storage used to store the object. Choices:
|
|
Specifies the number of days an object is noncurrent before Amazon S3 can perform the associated action. |
|
Container for the transition rule that describes when noncurrent objects transition to the If your bucket is versioning-enabled (or versioning is suspended), you can set this action to request that Amazon S3 transition noncurrent object versions to the |
|
Specified the number of newer noncurrent and current versions that must exists before performing the associated action. |
|
The class of storage used to store the object. Choices:
|
|
Specifies the number of days an object is noncurrent before Amazon S3 can perform the associated action. |
|
Not Provived. |
|
Not Provived. |
|
Not Provived. |
|
Not Provived. Choices:
|
|
Tags to use to identify a subset of objects for an Amazon S3 bucket. |
|
Not Provived. |
|
Not Provived. |
|
You must specify at least one of transition_date and transition_in_days. |
|
Not Provived. Choices:
|
|
The date value in ISO 8601 format. The timezone is always UTC. (YYYY-MM-DDThh:mm:ssZ). |
|
Not Provived. |
|
You must specify at least one of transition_date and transition_in_days. |
|
Not Provived. Choices:
|
|
The date value in ISO 8601 format. The timezone is always UTC. (YYYY-MM-DDThh:mm:ssZ). |
|
Not Provived. |
|
Settings that define where logs are stored. |
|
The name of an Amazon S3 bucket where Amazon S3 store server access log files. You can store log files in any bucket that you own. By default, logs are stored in the bucket where the logging_configuration property is defined. |
|
Not Provived. |
|
Settings that define a metrics configuration for the CloudWatch request metrics from the bucket. |
|
Not Provived. |
|
Not Provived. |
|
Not Provived. |
|
Tags to use to identify a subset of objects for an Amazon S3 bucket. |
|
Not Provived. |
|
Not Provived. |
|
Configuration that defines how Amazon S3 handles bucket notifications.Describes the notification configuration for an Amazon S3 bucket. |
|
Describes the Amazon EventBridge notification configuration for an Amazon S3 bucket. |
|
Specifies whether to send notifications to Amazon EventBridge when events occur in an Amazon S3 bucket. Choices:
|
|
Describes the AWS Lambda functions to invoke and the events for which to invoke them. |
|
The Amazon S3 bucket event for which to invoke the AWS Lambda function. |
|
The filtering rules that determine which objects invoke the AWS Lambda function.Specifies object key name filtering rules. |
|
A container for object key name prefix and suffix filtering rules. |
|
Specifies the Amazon S3 object key name to filter on and whether to filter on the suffix or prefix of the key name. |
|
Not Provived. |
|
Not Provived. |
|
The Amazon Resource Name (ARN) of the AWS Lambda function that Amazon S3 invokes when the specified event type occurs. |
|
The Amazon Simple Queue Service queues to publish messages to and the events for which to publish messages. |
|
The Amazon S3 bucket event about which you want to publish messages to Amazon SQS. |
|
The filtering rules that determine which objects trigger notifications. |
|
A container for object key name prefix and suffix filtering rules. |
|
Specifies the Amazon S3 object key name to filter on and whether to filter on the suffix or prefix of the key name. |
|
Not Provived. |
|
Not Provived. |
|
The Amazon Resource Name (ARN) of the Amazon SQS queue to which Amazon S3 publishes a message when it detects events of the specified type. |
|
The topic to which notifications are sent and the events for which notifications are generated. |
|
The Amazon S3 bucket event about which to send notifications. |
|
The filtering rules that determine for which objects to send notifications. |
|
A container for object key name prefix and suffix filtering rules. |
|
Specifies the Amazon S3 object key name to filter on and whether to filter on the suffix or prefix of the key name. |
|
Not Provived. |
|
Not Provived. |
|
The Amazon Resource Name (ARN) of the Amazon SNS topic to which Amazon S3 publishes a message when it detects events of the specified type. |
|
Places an Object Lock configuration on the specified bucket. |
|
Not Provived. Default: |
|
The Object Lock rule in place for the specified object. |
|
The default retention period that you want to apply to new objects placed in the specified bucket. |
|
Not Provived. |
|
Not Provived. Choices:
|
|
Not Provived. |
|
Indicates whether this bucket has an Object Lock configuration enabled. Choices:
|
|
Specifies the container element for object ownership rules. |
|
Not Provived. |
|
Specifies an object ownership rule. Choices:
|
|
A named AWS profile to use for authentication. See the AWS documentation for more information about named profiles https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html. The The profile option is mutually exclusive with the aws_access_key, aws_secret_key and security_token options. |
|
Configuration that defines how Amazon S3 handles public access. |
|
Specifies whether Amazon S3 should block public access control lists (ACLs) for this bucket and objects in this bucket. Setting this element to
Enabling this setting doesnt affect existing policies or ACLs. Choices:
|
|
Specifies whether Amazon S3 should block public bucket policies for this bucket. Setting this element to Enabling this setting doesnt affect existing bucket policies. Choices:
|
|
Specifies whether Amazon S3 should ignore public ACLs for this bucket and objects in this bucket. Setting this element to Enabling this setting doesnt affect the persistence of any existing ACLs and doesnt prevent new public ACLs from being set. Choices:
|
|
Specifies whether Amazon S3 should restrict public bucket policies for this bucket. Setting this element to Enabling this setting doesnt affect previously stored bucket policies, except that public and cross-account access within any public bucket policy, including non-public delegation to specific accounts, is blocked. Choices:
|
|
Remove tags not listed in tags. Choices:
|
|
The AWS region to use. For global services such as IAM, Route53 and CloudFront, region is ignored. The See the Amazon AWS documentation for more information http://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region. The Support for the |
|
Configuration for replicating objects in an S3 bucket.A container for replication rules. You can add up to 1,000 rules. The maximum size of a replication configuration is 2 MB. |
|
The Amazon Resource Name (ARN) of the AWS Identity and Access Management (IAM) role that Amazon S3 assumes when replicating objects. |
|
Specifies which Amazon S3 objects to replicate and where to store the replicas. |
|
Not Provived. |
|
Not Provived. Choices:
|
|
Specifies which Amazon S3 bucket to store replicated objects in and their storage class. |
|
Specify this only in a cross-account scenario (where source and destination bucket owners are not the same), and you want to change replica ownership to the AWS account that owns the destination bucket. If this is not specified in the replication configuration, the replicas are owned by same AWS account that owns the source object. |
|
Not Provived. Default: |
|
Not Provived. |
|
Not Provived. |
|
Specifies encryption-related information for an Amazon S3 bucket that is a destination for replicated objects. |
|
Specifies the ID (Key ARN or Alias ARN) of the customer managed customer master key (CMK) stored in AWS Key Management Service (KMS) for the destination bucket. |
|
Not Provived. |
|
Not Provived. |
|
Not Provived. |
|
Not Provived. Choices:
|
|
Not Provived. |
|
Not Provived. Choices:
|
|
Not Provived. |
|
Not Provived. |
|
The storage class to use when replicating objects, such as S3 Standard or reduced redundancy. Choices:
|
|
Not Provived. |
|
Not Provived. |
|
Not Provived. |
|
Tags to use to identify a subset of objects for an Amazon S3 bucket. |
|
Not Provived. |
|
Not Provived. |
|
Not Provived. |
|
Tags to use to identify a subset of objects for an Amazon S3 bucket. |
|
Not Provived. |
|
Not Provived. |
|
A unique identifier for the rule. |
|
An object key name prefix that identifies the object or objects to which the rule applies. |
|
Not Provived. |
|
A container that describes additional filters for identifying the source objects that you want to replicate. |
|
A filter that you can specify for selection for modifications on replicas. |
|
Specifies whether Amazon S3 replicates modifications on replicas. Choices:
|
|
A container for filter information for the selection of Amazon S3 objects encrypted with AWS KMS.A container for filter information for the selection of S3 objects encrypted with AWS KMS. |
|
Specifies whether Amazon S3 replicates objects created with server-side encryption using a customer master key (CMK) stored in AWS Key Management Service. Choices:
|
|
Specifies whether the rule is enabled. Choices:
|
|
AWS secret access key. See the AWS documentation for more information about access tokens https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys. The The secret_key and profile options are mutually exclusive. The aws_secret_access_key alias was added in release 5.1.0 for consistency with the AWS botocore SDK. The ec2_secret_key alias has been deprecated and will be removed in a release after 2024-12-01. Support for the |
|
AWS STS session token for use with temporary credentials. See the AWS documentation for more information about access tokens https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys. The The security_token and profile options are mutually exclusive. Aliases aws_session_token and session_token were added in release 3.2.0, with the parameter being renamed from security_token to session_token in release 6.0.0. The security_token, aws_security_token, and access_token aliases have been deprecated and will be removed in a release after 2024-12-01. Support for the |
|
Goal state for resource. state=present creates the resource if it doesn’t exist, or updates to the provided state if the resource already exists. state=absent ensures an existing instance is deleted. state=list get all the existing resources. state=describe or state=get retrieves information on an existing resource. Choices:
|
|
A dict of tags to apply to the resource. To remove all tags set tags={} and purge_tags=true. |
|
When set to Setting validate_certs=false is strongly discouraged, as an alternative, consider setting aws_ca_bundle instead. Choices:
|
|
Describes the versioning state of an Amazon S3 bucket. |
|
The versioning state of the bucket. Choices:
|
|
Wait for operation to complete before returning. Choices:
|
|
How many seconds to wait for an operation to complete before timing out. Default: |
|
Specifies website configuration parameters for an Amazon S3 bucket. |
|
The name of the error document for the website. |
|
The name of the index document for the website. |
|
Specifies the redirect behavior of all requests to a website endpoint of an Amazon S3 bucket. |
|
Name of the host where requests are redirected. |
|
Protocol to use when redirecting requests. The default is the protocol that is used in the original request. Choices:
|
|
Specifies the redirect behavior and when a redirect is applied. |
|
Container for redirect information. You can redirect requests to another host, to another page, or with another protocol. In the event of an error, you can specify a different error code to return.Specifies how requests are redirected. In the event of an error, you can specify a different error code to return. |
|
The host name to use in the redirect request. |
|
The HTTP redirect code to use on the response. Not required if one of the siblings is present. |
|
Protocol to use when redirecting requests. The default is the protocol that is used in the original request. Choices:
|
|
The object key prefix to use in the redirect request. |
|
The specific object key to use in the redirect request.d. |
|
A container for describing a condition that must be met for the specified redirect to apply.You must specify at least one of http_error_code_returned_equals and key_prefix_equals. |
|
The HTTP error code when the redirect is applied. |
|
The object key name prefix when the redirect is applied. |
Notes
Note
Caution: For modules, environment variables and configuration files are read from the Ansible ‘host’ context and not the ‘controller’ context. As such, files may need to be explicitly copied to the ‘host’. For lookup and connection plugins, environment variables and configuration files are read from the Ansible ‘controller’ context and not the ‘host’ context.
The AWS SDK (boto3) that Ansible uses may also read defaults for credentials and other settings, such as the region, from its configuration files in the Ansible ‘host’ context (typically
~/.aws/credentials
). See https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html for more information.
Examples
- name: Create S3 bucket
amazon.cloud.s3_bucket:
bucket_name: '{{ bucket_name }}'
state: present
register: output
- name: Describe S3 bucket
amazon.cloud.s3_bucket:
state: describe
bucket_name: '{{ output.result.identifier }}'
register: _result
- name: List S3 buckets
amazon.cloud.s3_bucket:
state: list
register: _result
- name: Update S3 bucket public access block configuration and tags (diff=true)
amazon.cloud.s3_bucket:
bucket_name: '{{ output.result.identifier }}'
state: present
public_access_block_configuration:
block_public_acls: false
block_public_policy: false
ignore_public_acls: false
restrict_public_buckets: false
tags:
mykey: myval
diff: true
register: _result
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
---|---|
When state=list, it is a list containing dictionaries of resource information. Otherwise, it is a dictionary of resource information. When state=absent, it is an empty dictionary. Returned: always |
|
The unique identifier of the resource. Returned: success |
|
The resource properties. Returned: success |