![](/img/trans.png)
[英]AWS API Gateway - Lambda Proxy not turning on via CloudFormation template
[英]how to add api gateway ( with api key) to an exiting lambda cloudformation template?
我正在學習 SAM Cli 並使用 lambda function 的現有模板。 我不是 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 key ,你必須在你的模板中使用三個組件:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.