如何使用 AWS CloudFormation 在 AWS API Gateway 上应用安全策略?

Ani*_*aje 5 amazon-web-services aws-cloudformation aws-api-gateway

我有一个简单的 cloudformation 模板,它正在为 API 网关创建自定义域,
该模板能够创建自定义域。

但我找不到将其设置为的 cloudformation 属性Custom Domain Security PolicyTLS 1.2
模板使用默认值创建自定义域TLS 1.0 Security Policy

模板 -

AWSTemplateFormatVersion: 2010-09-09
Transform: 'AWS::Serverless-2016-10-31'
Description: Test Custom Domain

Resources:
  test:
    Type: AWS::ApiGateway::DomainName
    Properties: 
      CertificateArn: !Sub 'arn:aws:acm:${AWS::Region}:${AWS::AccountId}:certificate/xxxx-xxx-xxx-xxxx-xxxx'
      DomainName: 'test-api.example.com'
      EndpointConfiguration: 
        Types: 
          - 'EDGE'
Run Code Online (Sandbox Code Playgroud)

参考 -
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-domainname.html

小智 5

2020 年 7 月添加了对在 API 网关域上指定安全策略的支持。AWS 文档上提供了有关如何将此参数添加到 CloudFormation 模板的文档。安全策略的有效值为TLS_1_0TLS_1_2。下面的例子:

ApiCustomDomainName:
  Type: 'AWS::ApiGateway::DomainName'
  Condition: ApiGatewayEnabled
  Properties:
    DomainName: "example.com"
    RegionalCertificateArn: !Ref CertificateArn
    securityPolicy: "TLS_1_2"
      EndpointConfiguration:
        Types:
          - REGIONAL
Run Code Online (Sandbox Code Playgroud)


Mat*_*Mat 3

遗憾的是,该参数尚未通过 CloudFormation 公开。

这里有一张票跟踪其进展 - https://github.com/aws-cloudformation/aws-cloudformation-coverage-roadmap/issues/3

目前,您最好的选择是创建自定义 CloudFormation 资源。

此参数通过 API 公开,并且可以由(至少部分)其 SDK 使用 - https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/apigateway.html#APIGateway.Client .create_domain_name

以下是讨论如何创建客户资源的文档 - https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-custom-resources.html