Set Scaleway Bucket Policy
scaleway_s3_put_bucket_policyReplace an entire Scaleway S3 bucket policy with a JSON document. Use to set or overwrite access rules; first get the existing policy to merge new statements without losing current grants.
Instructions
Replace a bucket's entire Bucket Policy with the given JSON document. This is the bucket-scoped half of access control - see scaleway_iam_create_policy's description for why both an IAM Policy and a Bucket Policy are needed together. Recommended safety net: include a statement granting the bucket owner's own user_id full access (mirrors the console's 'Maintain access to bucket' checkbox) so a mistake here can never lock the account out of its own bucket.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| bucket | Yes | Bucket name, e.g. 'payments-backups'. | |
| region | No | Region the bucket lives in. Defaults to the server's configured region (fr-par). | |
| policy_json | Yes | The COMPLETE bucket policy document as a JSON string (not a JS object) - this call REPLACES the entire existing policy, it does not merge. To add a statement without losing existing grants, call scaleway_s3_get_bucket_policy first, add your statement to its Statement array, then PUT the merged document. Known gotcha: 's3:HeadObject' is NOT a valid action here (HeadObject/HeadBucket calls are authorized via 's3:GetObject'/'s3:ListBucket' respectively) - submitting it fails with 'Policy has invalid action'. Despite the AWS-compatible API/SDK, 'Resource' entries are BARE bucket names, NOT ARNs - use 'my-bucket' and 'my-bucket/*', not 'arn:aws:s3:::my-bucket' (submitting an ARN fails with 'Policy has invalid resource', confirmed empirically 2026-08-18). To grant an application_id Principal, 'Version' must be '2023-04-17' (not AWS's '2012-10-17') - example: {"Version":"2023-04-17","Statement":[{"Sid":"Example","Effect":"Allow","Principal":{"SCW":"application_id:<uuid>"},"Action":["s3:GetObject","s3:ListBucket"],"Resource":["my-bucket","my-bucket/*"]}]}. Also remember an IAM Policy (scaleway_iam_create_policy) granting the SAME principal project-wide access to the relevant permission sets is required in addition to this bucket policy - a Bucket Policy alone is not sufficient on Scaleway. |