[英]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.