gpt4 book ai didi

amazon-web-services - AWS SAM : can we use a already existing api in aws sam template?

转载 作者:行者123 更新时间:2023-12-04 12:58:14 28 4
gpt4 key购买 nike

我有一个需要通过 Amazon API Gateway 触发的 lambda 函数。有没有办法将现有的 API(使用 AWS 控制台创建)包含到 AWS SAM 模板中?

最佳答案

SAM 尚不支持模板中的 !ImportValue。
Issue on Github
在 aws/serverless-application-model 的 GitHub 上,有一个针对该功能的公开 PR
See here
如果您愿意,您可以帮助并为该公关做出贡献,这样您就可以开始在您的 SAM template.yml 中使用 !ImportValue
否则,我建议您采用旧方法,使用 CloudFormation 模板创建 CI/CD,该模板可以使用 !ImportValue 并链接到您的 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 模板一样使用它
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-importvalue.html
请注意,这里我使用 Fn:ImportValue 因为我需要使用 !Sub 但如果您不需要在导入值中引用参数,只需使用 !ImportValue

关于amazon-web-services - AWS SAM : can we use a already existing api in aws sam template?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63232730/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com