S3事件未触发/未在Lambda UI中显示;使用无服务器CLI / serverless-plugin-existing-s3构建

时间:2019-05-08 19:29:20

标签: amazon-web-services amazon-s3 serverless aws-serverless

尽管SNS和SQS触发器会触发事件,但Lambda不会被事件触发,创建的事件也不会出现在Lambda GUI中。

这里是serverless.yml(注意:由于我偏执,我删除了我的ARN):

service: my-service

provider:
  name: aws
  runtime: python3.7
  iamRoleStatements:
    - Effect: "Allow"
      Action:
        - "s3:PutObject"
      Resource:
        Fn::Join:
          - ""
          - - "bucket-arn or *"

plugins:
  - serverless-plugin-existing-s3

layers:
  boto3_downgrade_layer:
    package:
      artifact: boto3_downgrade_layer.zip
    allowedAccounts:
      - '*'

functions:
  call_textract:
    handler: src/call_textract.lambda_handler
    description: "Kicks off the Textract process."
    events:
      - existings3:
          bucket: startrac-files
          event: s3:ObjectCreated:*
          rules:
            - prefix: input2/
            - suffix: .pdf
      - existings3:
          bucket: startrac-files
          event: s3:ObjectCreated:*
          rules:
            - prefix: input1/
            - suffix: .pdf
    layers:
      - arn

  get_textract_output:
    handler: src/get_textract_output.lambda_handler
    description: "Retrieves the Textracted data and writes it to a file to S3."
    events:
      - sqs: arn
    layers:
      - arn

  parse_textract_output:
    handler: src/parse_textract_output.lambda_handler
    description: "Parses the Textracted output and performs file ops in S3 based on the results."
    events:
      - sns: arn
    layers:
      - arn

要进行部署,我按照文档先运行sls deploy -v,然后运行sls s3deploy(没有错误),但是没有任何爱。我应该在UI的Lambda的“配置”部分中看到S3事件触发器(因为我在那里看到SQS / SNS触发器),但我没有。

今天我刚刚发现它时,我很可能在这里使用Serverless错误。

编辑1:只想指定我的名为call_textract的函数应由S3事件触发,而不是触发事件。

编辑2:我根据建议更新了代码。事件触发器显示在我的GUI中,除了它在右侧(由其触发),而不是在我需要的函数左侧。似乎我在这里使用Lambda错误。

1 个答案:

答案 0 :(得分:1)

您需要缩进bucketevents(使用s而不是event)和rules键(它们是{{1 }}事件),例如:

existingS3

您还需要functions: call_textract: handler: src/call_textract.lambda_handler description: "Kicks off the Textract process." events: - existingS3: # capital S bucket: startrac-files # defined under existingS3 events: - s3:ObjectCreated:* rules: - prefix: input2/ - suffix: .pdf 中正确的语句(除了其他语句):

iamRoleStatements