I'm trying to build a lambda function with s3 trigger throw the CDK deployment, does somebody knows if it possible to programmatically trigger the CDK code?
I found those links:
but they were a few months ago and I wanted to know if anything was renewed
if you want to trigger a lambda after a file was uploaded to S3 you have two ways:
S3 Eventnotifications:
this is a S3 specific feature and supports lambda as a target and also SQS and SNS. You can find more info here: https://docs.aws.amazon.com/AmazonS3/latest/dev/NotificationHowTo.html
CloudTrail:
CloudTrail logs pretty much all Events in your account and you can react to them if you want.
uploadBucket.onCloudTrailWriteObject('cwEvent', {
target: new targets.LambdaFunction()
})
this will create a CloudWatch Event.
On the first step you might need to also log it to cloud watch logs, I'm not sure anymore:
const trail = new cloudtrail.Trail(this, 'CloudTrail', {
sendToCloudWatchLogs: true,
managementEvents: cloudtrail.ReadWriteType.WRITE_ONLY,
});
I prefer version two, because CloudWatch Event supports way more targets than SQS, SNS and Lambda. I used it to trigger a Step Function for example.
Docs: https://docs.aws.amazon.com/cdk/api/latest/docs/aws-cloudtrail-readme.html https://docs.aws.amazon.com/cdk/api/latest/docs/aws-s3-readme.html#bucket-notifications
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.