AWS Amazon S3 Bucket Inventory

This page shows how to write Terraform and CloudFormation for Amazon S3 Bucket Inventory and write them securely.

aws_s3_bucket_inventory (Terraform)

The Bucket Inventory in Amazon S3 can be configured in Terraform with the resource name aws_s3_bucket_inventory. The following sections describe 5 examples of how to use the resource and its parameters.

Example Usage from GitHub

main.tf#L26
resource "aws_s3_bucket_inventory" "invtry_orc" {
  bucket = aws_s3_bucket.bucket_w_invtry.id
  name   = "EntireBucketDailyORC"

  included_object_versions = "All"

s3_bucket_inventory_test.tf#L20
resource "aws_s3_bucket_inventory" "inventory" {
  bucket                   = aws_s3_bucket.bucket1.bucket
  name                     = "inventory"
  included_object_versions = "All"

  schedule {
inventory.tf#L13
resource "aws_s3_bucket_inventory" "cache-inventory" {
  provider = aws.us
  bucket   = aws_s3_bucket.cache.id
  name     = "WeeklyInventory"

  included_object_versions = "All"
s3_bucket_inventory_test.tf#L20
resource "aws_s3_bucket_inventory" "inventory" {
  bucket                   = aws_s3_bucket.bucket1.bucket
  name                     = "inventory"
  included_object_versions = "All"

  schedule {
main.tf#L15
resource "aws_s3_bucket_inventory" "daily" {
  for_each = toset(var.bucket_list)

  bucket                   = each.key
  name                     = "FullBucketDailyInventory"
  included_object_versions = "All"

Review your Terraform file for AWS best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

Explanation in Terraform Registry

Provides a S3 bucket inventory configuration resource.

Tips: Best Practices for The Other AWS Amazon S3 Resources

In addition to the aws_s3_bucket_public_access_block, AWS Amazon S3 has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.

risk-label

aws_s3_bucket_public_access_block

Ensure S3 bucket-level Public Access Block restricts public bucket policies

It is better to enable S3 bucket-level Public Access Block if you don't need public buckets.

risk-label

aws_s3_bucket

Ensure S3 bucket access policy is well configured

It is better to configure the S3 bucket access policy properly to limit it unless explicitly required.

Review your AWS Amazon S3 settings

In addition to the above, there are other security points you should be aware of making sure that your .tf files are protected in Shisho Cloud.

AWS::S3::Bucket InventoryConfiguration (CloudFormation)

The Bucket InventoryConfiguration in S3 can be configured in CloudFormation with the resource name AWS::S3::Bucket InventoryConfiguration. The following sections describe how to use the resource and its parameters.

Example Usage from GitHub

An example could not be found in GitHub.

Parameters

Destination Contains information about where to publish the inventory results.
Required: Yes
Type: Destination
Update requires: No interruption

Enabled Specifies whether the inventory is enabled or disabled. If set to True, an inventory list is generated. If set to False, no inventory list is generated.
Required: Yes
Type: Boolean
Update requires: No interruption

Id The ID used to identify the inventory configuration.
Required: Yes
Type: String
Update requires: No interruption

IncludedObjectVersions Object versions to include in the inventory list. If set to All, the list includes all the object versions, which adds the version-related fields VersionId, IsLatest, and DeleteMarker to the list. If set to Current, the list does not contain these version-related fields.
Required: Yes
Type: String
Allowed values: All | Current
Update requires: No interruption

OptionalFields Contains the optional fields that are included in the inventory results.
Valid values: Size | LastModifiedDate | StorageClass | ETag | IsMultipartUploaded | ReplicationStatus | EncryptionStatus | ObjectLockRetainUntilDate | ObjectLockMode | ObjectLockLegalHoldStatus | IntelligentTieringAccessTier | BucketKeyStatus
Required: No
Type: List of String
Update requires: No interruption

Prefix Specifies the inventory filter prefix.
Required: No
Type: String
Update requires: No interruption

ScheduleFrequency Specifies the schedule for generating inventory results.
Allowed values: Daily | Weekly
Required: Yes
Type: String
Update requires: No interruption

Explanation in CloudFormation Registry

Specifies the inventory configuration for an Amazon S3 bucket. For more information, see GET Bucket inventory in the Amazon S3 API Reference.

Frequently asked questions

What is AWS Amazon S3 Bucket Inventory?

AWS Amazon S3 Bucket Inventory is a resource for Amazon S3 of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.

Where can I find the example code for the AWS Amazon S3 Bucket Inventory?

For Terraform, the benjdewantara/benjdewantara-iac, gilyas/infracost and NixOS/nixos-org-configurations source code examples are useful. See the Terraform Example section for further details.