如何解决如何将api网关带有api密钥添加到现有的lambda cloudformation模板中?
我正在学习SAM Cli,并正在使用lambda函数的现有模板。我不确定100%是否已使用此方法创建了API网关。但是,如果不是这样,我想通过添加一个api网关(可能带有api密钥的身份验证机制)来扩展它。另外,我还创建了具有私有/公共子网的VPC。我如何/在哪里可以在此模板中定义它们。任何代码示例都将有所帮助。
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Sample SAM Template
Globals:
Function:
Timeout: 3
Resources:
HelloWorldFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: hello_world/
Handler: app.lambda_handler
Runtime: python3.8
Events:
HelloWorld:
Type: Api # More info about API Event Source:
Properties:
Path: /hello
Method: get
Outputs:
HelloWorldApi:
Description: "API Gateway endpoint URL for Prod stage for Hello World function"
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/"
HelloWorldFunction:
Description: "Hello World Lambda Function ARN"
Value: !GetAtt HelloWorldFunction.Arn
HelloWorldFunctionIamRole:
Description: "Implicit IAM Role created for Hello World function"
Value: !GetAtt HelloWorldFunctionRole.Arn
解决方法
您尚未提供有关API geteway的任何模板代码。因此,通常,如果要使用 API密钥,则必须在模板中使用三个组件:
- AWS::ApiGateway::UsagePlan为api创建使用计划,
- AWS::ApiGateway::ApiKey创建 API密钥
- AWS::ApiGateway::UsagePlanKey将密钥与计划关联。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。