Hi! how can i do a s3 trigger with sst?
# help
m
Hi! how can i do a s3 trigger with sst?
f
Do u have an existing s3 bucket?
m
No
f
In your stack, define these at the top
Copy code
import * as s3 from '@aws-cdk/aws-s3';
import * as sst from "@serverless-stack/resources";
import { S3EventSource } from '@aws-cdk/aws-lambda-event-sources';
And the code looks something like this. Configure the bucket, and the bucket events u want to trigger the Lambda with.
Copy code
const bucket = new s3.Bucket(this, "MyBucket");
const lambda = new sst.Function(this, "MyFunction", {
	handler: "src/myFunction.main"
});
lambda.addEventSource(new S3EventSource(bucket, {
  events: [ s3.EventType.OBJECT_CREATED, s3.EventType.OBJECT_REMOVED ]
}));
We will create an
sst.Bucket
construct later to simply this
m
Nice thank you!