https://pulumi.com logo
#typescript
Title
# typescript
s

stocky-sundown-45608

05/25/2023, 12:34 PM
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

billowy-army-68599

05/25/2023, 12:41 PM
you can’t interpolate an output into json like that, you need to use an apply or
pulumi.jsonStringify
instead
s

stocky-sundown-45608

05/25/2023, 12:43 PM
aah okay, thanks for that. will evaluate it outside jsonStringify
s

stocky-sundown-45608

05/25/2023, 1:45 PM
thanks this helps 🙂