# Amazon S3 Message Body Storage Amazon S3 storage saves message bodies in an S3 bucket. Set `ServiceControl/MessageBody/StorageType` on an Error instance, or `ServiceControl.Audit/MessageBody/StorageType` on an Audit instance, to `S3` when the instance uses [SQL Server](/servicecontrol/storage/sqlserver/index.md) or [PostgreSQL](/servicecontrol/storage/postgresql/index.md) storage. ## Authentication Amazon S3 supports two authentication methods: - **Static keys** — configure `AccessKeyId` and `SecretAccessKey` together. Both must be set or both must be left empty. - **Ambient credentials** — when static keys are not set, the AWS SDK default credential chain resolves credentials, such as an IAM role attached to the compute resource. ## Required settings ### ServiceControl/MessageBody/S3/BucketName _Added in version 7.0.0_ The Amazon S3 bucket used to store message bodies when `MessageBody/StorageType` is `S3`. | Context | Name | | --- | --- | | **Environment variable** | `SERVICECONTROL_MESSAGEBODY_S3_BUCKETNAME` | | **App config key** | `ServiceControl/MessageBody/S3/BucketName` | | **SCMU field** | N/A | | Type | Default value | | --- | --- | | string | None (required for S3 storage) | ### ServiceControl.Audit/MessageBody/S3/BucketName _Added in version 7.0.0_ The Amazon S3 bucket used to store message bodies when `MessageBody/StorageType` is `S3`. | Context | Name | | --- | --- | | **Environment variable** | `SERVICECONTROL_AUDIT_MESSAGEBODY_S3_BUCKETNAME` | | **App config key** | `ServiceControl.Audit/MessageBody/S3/BucketName` | | **SCMU field** | N/A | | Type | Default value | | --- | --- | | string | None (required for S3 storage) | ## Optional settings ### ServiceControl/MessageBody/S3/KeyPrefix _Added in version 7.0.0_ The prefix applied to message body object keys in Amazon S3. | Context | Name | | --- | --- | | **Environment variable** | `SERVICECONTROL_MESSAGEBODY_S3_KEYPREFIX` | | **App config key** | `ServiceControl/MessageBody/S3/KeyPrefix` | | **SCMU field** | N/A | | Type | Default value | | --- | --- | | string | `error-bodies/` | ### ServiceControl.Audit/MessageBody/S3/KeyPrefix _Added in version 7.0.0_ The prefix applied to message body object keys in Amazon S3. Every Audit instance has the same default, so set a different key prefix for each Audit instance that uses the same bucket. The exception is Audit instances that [share a database](/servicecontrol/audit-instances/scaling-out-ingestion.md#sql-storage-shared-database), which must all use the same bucket and key prefix. | Context | Name | | --- | --- | | **Environment variable** | `SERVICECONTROL_AUDIT_MESSAGEBODY_S3_KEYPREFIX` | | **App config key** | `ServiceControl.Audit/MessageBody/S3/KeyPrefix` | | **SCMU field** | N/A | | Type | Default value | | --- | --- | | string | `audit-bodies/` | > [!WARNING] > Audit instances with different retention periods must use separate key prefixes when they share an S3 bucket. Audit instances use the same default key prefix, so explicitly configure a different `ServiceControl.Audit/MessageBody/S3/KeyPrefix` for each instance. Retention cleanup deletes objects by time prefix across the configured key prefix. An instance with shorter retention can delete bodies that another instance still needs, leaving message records visible but their bodies unavailable. ### ServiceControl/MessageBody/S3/Region _Added in version 7.0.0_ The AWS region containing the S3 bucket. When this setting is not specified, the AWS SDK resolves the region from its default configuration chain. | Context | Name | | --- | --- | | **Environment variable** | `SERVICECONTROL_MESSAGEBODY_S3_REGION` | | **App config key** | `ServiceControl/MessageBody/S3/Region` | | **SCMU field** | N/A | | Type | Default value | | --- | --- | | string | None | ### ServiceControl.Audit/MessageBody/S3/Region _Added in version 7.0.0_ The AWS region containing the S3 bucket. When this setting is not specified, the AWS SDK resolves the region from its default configuration chain. | Context | Name | | --- | --- | | **Environment variable** | `SERVICECONTROL_AUDIT_MESSAGEBODY_S3_REGION` | | **App config key** | `ServiceControl.Audit/MessageBody/S3/Region` | | **SCMU field** | N/A | | Type | Default value | | --- | --- | | string | None | ### ServiceControl/MessageBody/S3/ServiceUrl _Added in version 7.0.0_ The service URL for an S3-compatible storage provider. Leave this setting empty when using Amazon S3. | Context | Name | | --- | --- | | **Environment variable** | `SERVICECONTROL_MESSAGEBODY_S3_SERVICEURL` | | **App config key** | `ServiceControl/MessageBody/S3/ServiceUrl` | | **SCMU field** | N/A | | Type | Default value | | --- | --- | | string | None | ### ServiceControl.Audit/MessageBody/S3/ServiceUrl _Added in version 7.0.0_ The service URL for an S3-compatible storage provider. Leave this setting empty when using Amazon S3. | Context | Name | | --- | --- | | **Environment variable** | `SERVICECONTROL_AUDIT_MESSAGEBODY_S3_SERVICEURL` | | **App config key** | `ServiceControl.Audit/MessageBody/S3/ServiceUrl` | | **SCMU field** | N/A | | Type | Default value | | --- | --- | | string | None | ### ServiceControl/MessageBody/S3/AccessKeyId _Added in version 7.0.0_ The access key ID used to authenticate with S3. Configure this setting together with `ServiceControl/MessageBody/S3/SecretAccessKey`, or leave both empty to use the AWS SDK default credential chain. | Context | Name | | --- | --- | | **Environment variable** | `SERVICECONTROL_MESSAGEBODY_S3_ACCESSKEYID` | | **App config key** | `ServiceControl/MessageBody/S3/AccessKeyId` | | **SCMU field** | N/A | | Type | Default value | | --- | --- | | string | None | ### ServiceControl.Audit/MessageBody/S3/AccessKeyId _Added in version 7.0.0_ The access key ID used to authenticate with S3. Configure this setting together with `ServiceControl.Audit/MessageBody/S3/SecretAccessKey`, or leave both empty to use the AWS SDK default credential chain. | Context | Name | | --- | --- | | **Environment variable** | `SERVICECONTROL_AUDIT_MESSAGEBODY_S3_ACCESSKEYID` | | **App config key** | `ServiceControl.Audit/MessageBody/S3/AccessKeyId` | | **SCMU field** | N/A | | Type | Default value | | --- | --- | | string | None | ### ServiceControl/MessageBody/S3/SecretAccessKey _Added in version 7.0.0_ The secret access key used to authenticate with S3. Configure this setting together with `ServiceControl/MessageBody/S3/AccessKeyId`, or leave both empty to use the AWS SDK default credential chain. | Context | Name | | --- | --- | | **Environment variable** | `SERVICECONTROL_MESSAGEBODY_S3_SECRETACCESSKEY` | | **App config key** | `ServiceControl/MessageBody/S3/SecretAccessKey` | | **SCMU field** | N/A | | Type | Default value | | --- | --- | | string | None | ### ServiceControl.Audit/MessageBody/S3/SecretAccessKey _Added in version 7.0.0_ The secret access key used to authenticate with S3. Configure this setting together with `ServiceControl.Audit/MessageBody/S3/AccessKeyId`, or leave both empty to use the AWS SDK default credential chain. | Context | Name | | --- | --- | | **Environment variable** | `SERVICECONTROL_AUDIT_MESSAGEBODY_S3_SECRETACCESSKEY` | | **App config key** | `ServiceControl.Audit/MessageBody/S3/SecretAccessKey` | | **SCMU field** | N/A | | Type | Default value | | --- | --- | | string | None | ## Setup and runtime Setup creates the configured bucket if it does not exist. To check for the bucket, setup reads the bucket's access control list, so the identity used for setup needs `s3:GetBucketAcl` and, to create the bucket, `s3:CreateBucket`. If setup cannot read the access control list, it assumes the bucket exists and does not create it; create the bucket in advance when the setup identity lacks these permissions. The runtime identity needs `s3:GetObject`, `s3:PutObject`, and `s3:DeleteObject` on objects in the bucket, and `s3:ListBucket` on the bucket itself. The retention sweeper deletes body objects before removing the corresponding database records. > [!WARNING] > Grant `s3:ListBucket` to the runtime identity. Before storing a body, ServiceControl checks whether the object already exists. Without `s3:ListBucket`, Amazon S3 answers that check for a missing object with `403 Forbidden` instead of `404 Not Found`, and every message body that goes to the external store fails to be stored. For S3-compatible storage, set `ServiceUrl` to the endpoint URL. ServiceControl uses path-style addressing when a service URL is configured. Leave `ServiceUrl` unset when using Amazon S3. Set these variables in the instance's environment to use static keys. Replace the credential placeholders with secrets supplied by the deployment environment: ```text SERVICECONTROL_MESSAGEBODY_STORAGETYPE=S3 SERVICECONTROL_MESSAGEBODY_S3_BUCKETNAME=servicecontrol-bodies SERVICECONTROL_MESSAGEBODY_S3_ACCESSKEYID=... SERVICECONTROL_MESSAGEBODY_S3_SECRETACCESSKEY=... SERVICECONTROL_MESSAGEBODY_S3_REGION=us-east-1 ``` Example environment variables using ambient credentials: ```text SERVICECONTROL_MESSAGEBODY_STORAGETYPE=S3 SERVICECONTROL_MESSAGEBODY_S3_BUCKETNAME=servicecontrol-bodies SERVICECONTROL_MESSAGEBODY_S3_REGION=us-east-1 ``` Audit instances use the same settings with the `SERVICECONTROL_AUDIT_` prefix. Set a key prefix for each Audit instance that uses the same bucket, except Audit instances that [share a database](/servicecontrol/audit-instances/scaling-out-ingestion.md#sql-storage-shared-database): ```text SERVICECONTROL_AUDIT_MESSAGEBODY_STORAGETYPE=S3 SERVICECONTROL_AUDIT_MESSAGEBODY_S3_BUCKETNAME=servicecontrol-bodies SERVICECONTROL_AUDIT_MESSAGEBODY_S3_KEYPREFIX=audit-instance1/ SERVICECONTROL_AUDIT_MESSAGEBODY_S3_REGION=us-east-1 ``` See the [external message body storage overview](/servicecontrol/storage/external-body/index.md) for shared configuration, retention, and backup guidance.