localstack / serverless-localstack

⚡ Serverless plugin for running against LocalStack
519 stars 83 forks source link

Unable to create S3 trigger with `existing: true` parameter #206

Closed codeeno closed 9 months ago

codeeno commented 1 year ago

Hello everyone!

I'm currently running into issues when trying to create a Lambda which uses an s3:ObjectCreated:* event from an existing S3 bucket as its trigger. While I am able to create the Lambda function itself, the S3 trigger does not seem to be added.

Localstack outputs the following warning:

2023-01-24T09:05:15.492  WARN --- [uncthread105] l.u.c.template_deployer    : Unable to deploy resource type "S3": {"Type": "Custom::S3", "Version": 1, "DependsOn": ["MyDashtestDashfunctionLambdaFunction", "CustomDashresourceDashexistingDashs3LambdaFunction"], "LogicalResourceId": "MyDashtestDashfunctionCustomS31", "Properties": {"ServiceToken": "arn:aws:lambda:us-east-1:000000000000:function:my-test-service-local-custom-resource-existing-s3", "FunctionName": "my-test-service-local-my-test-function", "BucketName": "my-test-bucket", "BucketConfigs": [{"Event": "s3:ObjectCreated:*", "Rules": [{"Prefix": "test/prefix"}, {"Suffix": ".txt"}]}]}}

I'm not sure if this is a bug or if I'm forgetting something.

Steps to reproduce

  1. Spin up localstack: docker run --rm --name localstack --network="localstack-network" -it -p 4566:4566 -p 4510-4559:4510-4559 localstack/localstack
  2. Create an S3 bucket: awslocal s3api create-bucket --bucket my-test-bucket --region us-east-1
  3. Create a serverless.yaml with the following content:
    
    service: my-test-service

provider: name: aws stage: development region: us-east-1

custom: localstack: stages:

plugins:

functions: my-test-function: memorySize: 128 runtime: nodejs16.x timeout: 40 handler: ./index.handler events:

The Lambda function does not get triggered.

When doing the above setup without creating an S3 bucket and commenting out the existing: true line, the Lambda does get triggered when putting an object.

asztal commented 1 year ago

I had the same issue and ended up just defining the NotificationConfiguration myself for that bucket in the Resources section of serverless.yml. Of course, this only works if the bucket is defined in the same stack.

                BucketName: foo
                NotificationConfiguration:
                    LambdaConfigurations:
                        - Event: s3:ObjectCreated:*
                          Function: !GetAtt SomeLambdaFunction.Arn
steffyP commented 11 months ago

Hi @codeeno,

could you check if you still see this error with the latest version of localstack? We recently fixed a related issue.

steffyP commented 9 months ago

This issue seems to be stale. As we didn't get any response in two months, we are closing this issue now. Please feel free to reopen if it still persists, and provide updates logs and details.