【问题标题】:AWS cloudformation domain names and API mappingsAWS cloudformation 域名和 API 映射
【发布时间】:2022-01-20 16:45:20
【问题描述】:

我有一个域名 example.com 和一个带有 api 网关的 lambda 后端,它使用以下 yaml 模板设置了云形成和代码管道:

 PostSomeApi:
      Type: AWS::Serverless::Function
      Properties:
       Handler: lambda_function.lambda_handler
       Runtime: python3.8
       FunctionName: some-api-name
       CodeUri: ./src/some-api-name 
       Role: !Ref LambdaRoleArn
       Timeout: 45
       Environment:
        Variables:
          accountId: !Ref "AWS::AccountId"
          region:    !Ref "AWS::Region"
       Events:
        SampleApi:
         Type: Api
         Properties:
          Path: /someapiname
          Method: POST

我使用控制台上的手动配置将子域 api.example.com 连接到 lambda api 网关,但现在我想将此 API 映射包含在云形成 yaml 模板中。

我该怎么做? This is the manual configuration of the api mapping

【问题讨论】:

  • 进展如何?仍然不清楚你能做什么?
  • 您好,感谢您要求我创建一个 AWS::Serverless::Api 和一个域,但后来我仍在努力处理 API 映射:MyDomainDev:类型:AWS::ApiGateway::DomainName 属性: 域名: api-dev.example.com CertificateArn: !Sub 'arn:aws:acm:us-east-1:${AWS::AccountId}:certificate/a2c90924-*****' EndpointConfiguration: 类型: - EDGE 安全策略:TLS_1_2
  • SampleFunction: Type: AWS::Serverless::Function Properties: Handler: Index.lambda_handler Runtime: python3.7 FunctionName: SamplePython CodeUri: ./src/nominal #Directory源文件是Role: !子 arn:aws:iam::${AWS::AccountId}:role/LambdaRole 环境:变量:accountId: !Ref "AWS::AccountId" region: !Ref "AWS::Region" 事件:SampleApi:类型:Api属性:路径:/sample-test 方法:GET RestApiId:参考:SampleApi
  • SampleApi:类型:AWS::Serverless::Api 属性:StageName:Test OpenApiVersion:'2.0' 域:MyDomainDev
  • APIMapping: Type: AWS::ApiGateway::BasePathMapping Properties: BasePath: example ( or empty ) DomainName: api-dev.example.com RestApiId: SampleApi Stage: dev

标签: amazon-web-services aws-lambda amazon-cloudformation aws-api-gateway


【解决方案1】:

您必须创建AWS::Serverless::Api,而不是手动执行此操作,您可以在其中提供DomainConfiguration

【讨论】:

  • 感谢您的回答。您的意思是用AWS::Serverless::Api 替换正在创建APIGateway 的Events: SampleApi: Type: Api Properties: Path: /someapiname Method: POST?你能放一个示例代码吗?
  • @philiot 是的。您创建自己的 AWS::Serverless::Api。
猜你喜欢
  • 1970-01-01
  • 2017-06-21
  • 1970-01-01
  • 1970-01-01
  • 2018-08-30
  • 2018-02-03
  • 1970-01-01
  • 1970-01-01
  • 2021-12-30
相关资源
最近更新 更多