Can a S3 bucket and triggered Lambda be created in separate CloudFormation templates. I want to keep long running resources stack separate from the likes of Lambda which get updated quite frequently
When tried to create Lambda separately it says that bucket defined in lambda event should be defined in same template and cannot be referenced.
S3 events must reference an S3 bucket in the same template.
GetFileMetadata:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub '${targetenv}-lambdaname'
CodeUri: target-file-0.0.1-SNAPSHOT.jar
Handler: LambdaFunctionHandler::handleRequest
Runtime: java8
Timeout: 30
MemorySize: 512
Environment:
Variables:
STAGE: !Sub '${targetenv}'
Events:
S3Event:
Type: S3
Properties:
Bucket:
Ref: MyS3Bucket
Events:
- 's3:ObjectCreated:*'
MyS3Bucket:
Type: 'AWS::S3::Bucket'
DependsOn: BucketPermission
Properties:
BucketName: !Sub 'bucketname-${targetenv}'