-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(race condition): Apply bucket policies to avoid race condition (#224
) (#230) * Apply bucket policies in a different way, to temporarily get around cms active remediation race conditions * Add a force override * Make it clear that these are custom resources
- Loading branch information
Showing
2 changed files
with
51 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Handler } from "aws-lambda"; | ||
import { send, SUCCESS, FAILED } from "cfn-response-async"; | ||
type ResponseStatus = typeof SUCCESS | typeof FAILED; | ||
import { S3Client, PutBucketPolicyCommand } from '@aws-sdk/client-s3'; | ||
const s3 = new S3Client(); | ||
|
||
export const handler: Handler = async (event, context) => { | ||
console.log("request:", JSON.stringify(event, undefined, 2)); | ||
const responseData = {}; | ||
let responseStatus: ResponseStatus = SUCCESS; | ||
let Bucket = event.ResourceProperties.Bucket; | ||
let Policy = JSON.stringify(event.ResourceProperties.Policy); | ||
try { | ||
if (event.RequestType == "Create" || event.RequestType == "Update") { | ||
let resp = await s3.send(new PutBucketPolicyCommand({ Bucket, Policy })); | ||
console.log(resp) | ||
} | ||
} catch (error) { | ||
console.log(error); | ||
responseStatus = FAILED; | ||
} finally { | ||
console.log("finally"); | ||
await send(event, context, responseStatus, responseData); | ||
} | ||
}; |