Create an S3 Inventory configuration
📑 On this page
Part 67 of AWS from Zero. This lesson keeps the scope to one S3 behavior you can verify from the terminal.
What we are learning
S3 Inventory produces scheduled object listings that are better suited to repeated full-bucket analysis than live listing calls.
Before you run it
SOURCE_BUCKET="replace-with-source-bucket"
DEST_BUCKET="replace-with-inventory-destination"
ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)The destination must be in the same Region and must have a bucket policy that allows S3 Inventory delivery from the source.
Cost note: Inventory generation and destination storage are billable.
The command
cat > inventory.json <<EOF
{
"Destination": {
"S3BucketDestination": {
"AccountId": "$ACCOUNT_ID",
"Bucket": "arn:aws:s3:::$DEST_BUCKET",
"Format": "CSV",
"Prefix": "inventory"
}
},
"IsEnabled": true,
"Id": "DailyCurrentVersions",
"IncludedObjectVersions": "Current",
"Schedule": {"Frequency": "Daily"},
"OptionalFields": ["Size", "LastModifiedDate", "StorageClass", "EncryptionStatus"]
}
EOF
aws s3api put-bucket-inventory-configuration \
--bucket "$SOURCE_BUCKET" \
--id DailyCurrentVersions \
--inventory-configuration file://inventory.jsonA successful configuration command may return no output. Treat inspection as a separate required step.
Inspect the result
aws s3api get-bucket-inventory-configuration \
--bucket "$SOURCE_BUCKET" \
--id DailyCurrentVersionsConfirm the destination ARN, schedule, version scope, and optional fields.
One tiny variation
aws s3api list-bucket-inventory-configurations \
--bucket "$SOURCE_BUCKET" \
--query "InventoryConfigurationList[].{ID:Id,Enabled:IsEnabled,Frequency:Schedule.Frequency}" \
--output tableA bucket can have multiple independently named inventory configurations.
Common mistake
The first report is not immediate, and the inventory destination exposes object metadata to readers of that destination. Protect it accordingly.
Cleanup
aws s3api delete-bucket-inventory-configuration \
--bucket "$SOURCE_BUCKET" \
--id DailyCurrentVersions
rm inventory.jsonDelete the configuration and separately decide whether delivered inventory reports should be retained.
Next, we will learn List and inspect S3 Inventory configurations.