我正在使用无服务器在python中编写lambda函数。在s3存储桶中创建文件时会触发lambda函数。 lambda函数转换文件,然后将其放入另一个存储桶。源s3存储桶在另一个堆栈中定义,目标存储桶在lambda函数的堆栈中定义。我一直试图找到一个例子来看看如何在环境变量中指定源桶以及在lambda函数的事件下?
service: Service
provider:
name: aws
runtime: python2.7
stage: ${opt:stage, 'dev'}
region: us-east-1
role: LambdaRole
functions:
LambdaFunction:
name: lambda-function
handler: handler.lambda_handler
environment:
DESTINATION_BUCKET: !Ref DestinationBucket
SOURCE_BUCKET: !Ref AnotherStack.SourceBucket # Is this correct?
event:
s3:
name: SOURCE_BUCKET # How do I reference a bucket from another stack here?
# ... other event trigger releated stuff
resources:
Resources:
LambdaRole:
Type: AWS:IAM:Role
Properties:
# .... lambda role permissions
DestinationBucket:
DeletionPolicy: Retain
Type: AWS::S3::Bucket
Properties:
AccessControl: BucketOwnerFullControl
BucketName:
!Join ['-', [destination-bucket !Ref AWS::AccountId]]
VersioningConfiguration:
Status: Suspended
SOURCE_BUCKET在另一个名为“AnotherStack”的堆栈中定义。存储桶的名称是“SourceBucket”。如果可能的话,我不想在无服务器的yml中硬编码堆栈名称,并执行类似于cloudformation模板提供的参数。所以问题是如何在lambda的无服务器.yml中引用它。