Serverless helps you with functions as a service across multiple providers. Using serverless with AWS allows you to tie these functions into your AWS infrastructure, or tie it into existing resources. Previously you couldn’t use existing S3 buckets for serverless lambda events. Today I learned that you can now use existing buckets.
Serverless offers a lot of AWS Lambda events to hook into for triggering your lambda when some action occurs across your infrastructure or resources. One of those resources is S3 for events like when an object is created. Previously serverless did not have a way of handling these events when the S3 bucket already existed.
Per the Serverless documentation, the option to allow existing buckets is only
available as of
v.1.47.0 and greater. You can see the example in the docs to read up on the other important notes provided. The
way to configure your serverless functions to allow existing S3 buckets is simple
and requires you to only set
existing: true on your S3 event as so:
functions: s3ObjectCreated: handler: objectCreated events: - s3: bucket: existing-bucket-name event: s3:ObjectCreated:* existing: true
It’s as simple as that. There are some limitations that they call out in the documentation. But for most, this will likely work for your usecase.