-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
aws-cdk-lib/aws_s3: bucket.grantReadWrite missing PutObject* actions #18669
Comments
Having the same issue. Updated from new s3deploy.BucketDeployment(this, 'DeployDemoTxtFiles', {
sources: [s3deploy.Source.asset('./src/deployments/demo/')],
exclude: ['*'],
include: ['*.txt'],
destinationKeyPrefix: 'public/demo/',
destinationBucket: bucket,
accessControl: 'PublicRead',
contentType: 'plain/text',
}); Now we get “access denied” during deployment. Cloudwatch logs show the Lambda function does not have PutObject rights. |
Apparently this is partially intentional that
But there are few more And AWS IAM being a horrible trial-and-error mess, it's hard to figure out in advance what policy each API call needs :( |
This merge is likely the source of the error: #12391 The change in functionality should only be seen in newly created CDK projects, since the feature is gated behind a feature flag aws-cdk/packages/@aws-cdk/cx-api/lib/features.ts Lines 83 to 90 in 9940952
@shishkin @daniel-gato you're likely seeing the error since you've migrated to V2 which has all feature flags enabled by default. Specifically include this feature flag to disable it 🙂 |
@peterwoodworth Thanks for pointing to the culprit, I think you're right. Just to mention that await s3.send(
new PutObjectCommand({
Bucket: BUCKET,
Key: `path/to/some/file.html`,
Tagging: new URLSearchParams({
foo: "bar",
}).toString(),
ContentType: "text/html; charset=UTF-8",
Body: html,
})
); |
As for |
Looks like that's already been done actually - #18494 specifically includes Is there anything else regarding this you need help with? |
Very cool! Look forward for this to be released 😀 |
I'd expect the next release by the end of next week 🙂 |
|
@peterwoodworth Ok, thank you for the clarification. I'm very new to CDK, when you say |
I tried to add the flag: Edit, while digging in the the code of my node_modules I can see this:
The only sure I'm not sure now is how to retrieve the principal of the BucketDeployment to pass it to this function on my bucket. |
@daniel-gato I'm sorry, I hadn't realized that the feature flags in v2 are only the specific ones documented in this link, and no other feature flags are toggleable. My mistake! Under the hood, the BucketDeployment construct creates both a lambda function and a custom resource. Both of which are written by the CDK team. So, this construct works fine for me normally on the current version. Maybe you're getting the error from somewhere else? What other infrastructure do you have in your code? |
What is the problem?
bucket.grantReadWrite(lambda)
misses additionalPutObject*
actions, probablyPutObjectTagging
orPutObjectAcl
. Issue is fixed by manually adding*
afterPutObject
in the policy actions list.Reproduction Steps
bucket.grantReadWrite(lambda)
with CDKWhat did you expect to happen?
If I grant lambda read and write I expect it to be able to write objects into S3
What actually happened?
AccessDenied from S3
CDK CLI Version
2.8.0
Framework Version
No response
Node.js Version
14
OS
MacOS
Language
Typescript
Language Version
No response
Other information
No response
The text was updated successfully, but these errors were encountered: