我有一个lambda函数,需要通过Amazon API Gateway触发。有没有办法将现有的API (使用AWS控制台创建)包含到AWS SAM模板中?
发布于 2020-12-14 02:05:49
SAM还不支持模板中的!ImportValue。
在aws/serverless- GitHub模型的应用程序上,该特性有一个开放的PR
如果你愿意,你可以帮助和贡献公关,这样你就可以开始在你的SAM template.yml中使用!ImportValue
否则,我建议您使用旧的方法,使用可以使用!ImportValue的CloudFormation模板创建CI/CD,并将其链接到您的lambda函数代码所在的S3存储桶。
Examples of Cloudformation Templates
更新
SAM CLI现在支持!ImportValue,Github上的问题已经解决。
您可以使用它,如下所示
# You need to export the resource that you want to use in another template first
# This goes at the end of your template.yml file, after the Resources
# template.yml in the first repo
Outputs:
myExportedResource:
Value: !Ref TheResource
Export:
Name: !Sub "{environment}-nice-export-name"
# template.yml in the second repo (This obviously goes in Resources)
MyLambda:
Type: AWS::Serverless::Function
Properties:
FunctionName: awesome-lambda
CodeUri: ./dist
Handler: this-file.handler
Role: !GetAtt LambdaRole.Arn
VpcConfig:
SecurityGroupIds:
- !GetAtt SecurityGroup.GroupId
SubnetIds:
- Fn::ImportValue: !Sub "${environment}-nice-export-name"您可以将其完全用作普通的cloudformation模板
注意,这里我使用了Fn:ImportValue,因为我需要使用!ImportValue,但是如果您不需要在导入值中引用参数,只需使用!Sub
https://stackoverflow.com/questions/63232730
复制相似问题