首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >AWS SAM:我们可以使用aws sam模板中已有的api吗?

AWS SAM:我们可以使用aws sam模板中已有的api吗?
EN

Stack Overflow用户
提问于 2020-08-03 23:51:46
回答 1查看 778关注 0票数 4

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

EN

回答 1

Stack Overflow用户

发布于 2020-12-14 02:05:49

SAM还不支持模板中的!ImportValue。

Issue on Github

在aws/serverless- GitHub模型的应用程序上,该特性有一个开放的PR

See here

如果你愿意,你可以帮助和贡献公关,这样你就可以开始在你的SAM template.yml中使用!ImportValue

否则,我建议您使用旧的方法,使用可以使用!ImportValue的CloudFormation模板创建CI/CD,并将其链接到您的lambda函数代码所在的S3存储桶。

Examples of Cloudformation Templates

更新

SAM CLI现在支持!ImportValue,Github上的问题已经解决。

您可以使用它,如下所示

代码语言:javascript
复制
# 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,因为我需要使用!ImportValue,但是如果您不需要在导入值中引用参数,只需使用!Sub

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63232730

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档