I am creating an s3 bucket with bucket policy howe...
# typescript
s
I am creating an s3 bucket with bucket policy however Pulumi complains about malformed policy in the resource but this works if I replace
${backendBucket.id}
with bucket name, not sure why it is in’t getting evaluated in JSON
Copy code
const backendBucket = new aws.s3.Bucket(`${bucketName}${environmentSuffix}`, {
    tags: {
        Environment: "dev",
    },

});

const bucketPolicy = JSON.stringify({

    Version: "2012-10-17",
    Statement: [{
        Effect: "Allow",
        Principal: "*",
        Action: [ 
            "s3:GetObject",
        ],
        Resource: [
            "arn:aws:s3:::${backendBucket.id}/*",
            "arn:aws:s3:::${backendBucket.id}"
        ]
    },

    ]
})
const backendBucketPolicy = new aws.s3.BucketPolicy("backend-bucket-policy", {
    bucket: backendBucket.id,
    policy: bucketPolicy,
});
b
you can’t interpolate an output into json like that, you need to use an apply or
pulumi.jsonStringify
instead
s
aah okay, thanks for that. will evaluate it outside jsonStringify
s
thanks this helps 🙂