A T*_*eja 5 api templates sam amazon-web-services
我有一个需要通过 Amazon API Gateway 触发的 lambda 函数。有没有办法将现有的 API(使用 AWS 控制台创建)包含到 AWS SAM 模板中?
SAM 尚不支持模板中的 !ImportValue。
在 aws/serverless-application-model 的 GitHub 上,有一个针对该功能的开放 PR
如果您希望可以为该 PR 提供帮助并做出贡献,那么您可以开始在 SAM template.yml 中使用 !ImportValue
否则,我建议您采用旧方法,使用 CloudFormation 模板创建 CI/CD,该模板可以使用 !ImportValue 并链接到 lambda 函数代码所在的 S3 存储桶。
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"
Run Code Online (Sandbox Code Playgroud)
您可以将其完全用作普通的 cloudformation 模板
请注意,这里我使用 Fn:ImportValue 因为我需要使用 !Sub 但如果您不需要在导入值中引用参数,只需使用 !ImportValue
| 归档时间: |
|
| 查看次数: |
2977 次 |
| 最近记录: |