[英]Lambda funciton not triggering after s3 upload
我试图在上传文件后触发 Lambda function 。
下面我定义了file
Lambda function。 在其中,一个文件被上传到 s3。 然后我想要触发process
Lambda function 。 但是,我无法触发它。 此外,在 AWS s3 中,存储桶属性 > 事件通知为空。
我的 serverless.yml:
service: backend
frameworkVersion: "2"
package:
exclude:
- "frontend/**"
plugins:
- serverless-python-requirements
custom:
pythonRequirements:
dockerizePip: true
dockerFile: ./dockerfile
provider:
name: aws
runtime: python2.7
stage: dev
lambdaHashingVersion: 20201221
apiGateway:
shouldStartNameWithService: true
environment:
STORAGE_BUCKET: dev-storage-bucket-01392334
iamRoleStatements:
- Effect: Allow
Action:
- s3:PutObject
- s3:PutObjectAcl
- s3:GetObject
- s3:GetObjectAcl
- s3:DeleteObject
Resource:
- "arn:aws:dynamodb:us-east-1:*:*"
- "arn:aws:s3:::*"
functions:
process:
handler: handler.process
events:
- s3:
bucket: ${self:provider.environment.STORAGE_BUCKET}
events: s3:ObjectCreated:*
existing: true
file:
handler: handler.file
events:
- http:
method: POST
path: /file
resources:
Resources:
storage:
Type: AWS::S3::Bucket
Properties:
BucketName: ${self:provider.environment.STORAGE_BUCKET}
在我的处理程序中,我有:
def process(event, context):
print("in process")
def fcsfile(event, context):
uploaded_file = event['body']
s3 = boto3.resource('s3')
object = s3.Object(STORAGE_BUCKET, 'the_file_name')
s3_response = object.put(Body=uploaded_file)
print(s3_response)
response = {
"statusCode": 200,
"body": json.dumps(response)
}
return response
当我对端点执行 CURL 时,文件会上传到 s3,但不会触发进程 function。
我试过删除'existing:true'。 结果相同。 我尝试将存储桶名称更改为完全不同的名称,例如“dev-storage-bucket-99999999968686”,但随后我看到了错误:
An error occurred: S3BucketDevstoragebucket99999999968686 - dev-storage-bucket-99999999968686 already exists in stack
不,存储桶不存在。
我还能尝试什么?
看起来你可能有一个小错字。
用handler.process
块中的event
替换events
似乎对我有用:
functions:
process:
handler: handler.process
events:
- s3:
bucket: ${self:provider.environment.STORAGE_BUCKET}
event: s3:ObjectCreated:*
existing: true
使用events
运行命令时,我收到来自无服务器框架的警告: Serverless: Configuration warning at 'functions.process.events[0]': unsupported function event
这是文档,它帮助我找到了正确的语法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.