amazon-web-servicesaws-lambdaserverless-frameworkserverlessaws-serverless

serverless Cannot have overlapping suffixes in two rules if the prefixes are overlapping for the same event type


I am trying to deploy AWS Lambda using Serverless framework and have following in serverless.yaml

provider:
  name: aws
  runtime: python3.8
  region: us-west-2
  stackName: ${self:service}-${self:custom.name}-${opt:stage, 'dev'}
  stackTags:
    Service: "it"
  lambdaHashingVersion: 20201221
  memorySize: 128
  timeout: 900
  logRetentionInDays: 14
  disableDefaultOutputExportNames: true
  deploymentBucket: ${self:custom.deployment-s3-bucket}
  environment:
    S3_BUCKET: ${self:custom.bucket}
    S3_BUCKET_PATH_PREFIX: ${self:custom.path_prefix}
    REDSHIFT_DATABASE: ${self:custom.database}
    REDSHIFT_SCHEMA: ${self:custom.schema}
    REDSHIFT_TABEL_PREFIX: ${self:custom.table_prefix}
    REDSHIFT_USER: ${self:custom.user}
    REDSHIFT_PASSWORD: ${self:custom.password}
    REDSHIFT_PORT: ${self:custom.port}
    REDSHIFT_ENDPOINT: ${self:custom.endpoint}
    REDSHIFT_ROLE: ${self:custom.role}
  iam:
    role:
      name: s3-to-redshift-load
      statements:
        - Effect: Allow
          Action:
            - s3:GetObject
          Resource: "arn:aws:s3:::${self:custom.bucket}/*"

functions:
  load:
    handler: handler.run
    events:
      - s3: #https://www.serverless.com/framework/docs/providers/aws/events/s3#using-existing-buckets
          bucket: ${self:custom.bucket}
          event: s3:ObjectCreated:*
          rules:
            - prefix: ${self:custom.path_prefix}/
            - suffix: .json
          existing: true

But when I deploy I get following error

Serverless Error ----------------------------------------

  An error occurred: LoadCustomS31 - Received response status [FAILED] from custom resource. Message returned: Configuration is ambiguously defined. Cannot have overlapping suffixes in two rules if the prefixes are overlapping for the same event type. See details in CloudWatch Log: 2021/08/30/[$LATEST]4f4f9ec564544ebb979576ed1b6b2879 (RequestId: 317ecd1c-b699-4799-8060-5168e1947e3c).

any idea what wrong I am doing here ?


Solution

  • Without knowing the details from the CloudWatch logs 2021/08/30/[$LATEST]4f4f9ec564544ebb979576ed1b6b2879 (RequestId: 317ecd1c-b699-4799-8060-5168e1947e3c) I would say that in your AWS account there is already a S3 event with the prefix ${self:custom.path_prefix}/ and the suffix .json on that bucket. It may be that it's there because of a previous or other serverless stack or that somebody created it manually and hasn't deleted it.

    Can you please check through the AWS console, that there are no other events on S3 with the same configuration?