Lambda UI 中的 S3 事件未 triggering/showing;使用无服务器构建 CLI/serverless-plugin-existing-s3
S3 event not triggering/showing up in Lambda UI; built with Serverless CLI/serverless-plugin-existing-s3
Lambda 不是由事件触发的,创建的事件也不会出现在 Lambda GUI 中,但 SNS 和 SQS 触发器会出现。
这里是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 触发器),但我没有。
我今天才发现,我很可能在这里使用了无服务器。
编辑 1:只是想指定我的名为 call_textract
的函数应该 由 S3 事件触发 ,而不是触发事件。
编辑 2:我按照建议更新了我的代码。事件触发器出现在我的 GUI 中,除了它在右侧(触发),而不是在我需要它的函数的左侧。好像我在这里用错了 Lambda。
您需要缩进 bucket
、events
(使用 s
,而不是 event
)和 rules
键(这些是您的 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
中的正确陈述(除了您的其他陈述):
provider:
name: aws
iamRoleStatements:
...
- Effect: "Allow"
Action:
- "s3:GetBucketNotification"
- "s3:PutBucketNotification"
Resource:
Fn::Join:
- ""
- - "arn:aws:s3:::BUCKET_NAME or *"
Lambda 不是由事件触发的,创建的事件也不会出现在 Lambda GUI 中,但 SNS 和 SQS 触发器会出现。
这里是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 触发器),但我没有。
我今天才发现,我很可能在这里使用了无服务器。
编辑 1:只是想指定我的名为 call_textract
的函数应该 由 S3 事件触发 ,而不是触发事件。
编辑 2:我按照建议更新了我的代码。事件触发器出现在我的 GUI 中,除了它在右侧(触发),而不是在我需要它的函数的左侧。好像我在这里用错了 Lambda。
您需要缩进 bucket
、events
(使用 s
,而不是 event
)和 rules
键(这些是您的 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
中的正确陈述(除了您的其他陈述):
provider:
name: aws
iamRoleStatements:
...
- Effect: "Allow"
Action:
- "s3:GetBucketNotification"
- "s3:PutBucketNotification"
Resource:
Fn::Join:
- ""
- - "arn:aws:s3:::BUCKET_NAME or *"