Amazon web services 如何在CDK应用程序中向API网关添加安全策略?

Amazon web services 如何在CDK应用程序中向API网关添加安全策略?,amazon-web-services,aws-api-gateway,aws-cdk,Amazon Web Services,Aws Api Gateway,Aws Cdk,我正在尝试在我的CDK应用程序中向我的API网关添加。但我不确定将其添加到我的API网关实例的何处: const api = new apiGateway.RestApi(this, "my-api", {..}) .. 当我将其部署到AWS时,我确实将端点视为 https://someid123.execute-api.us-east-1.amazonaws.com/prod 我猜这已经启用了TLS(使用https)?如果是,我如何查看实际使用的安全策略?为什么部署AP

我正在尝试在我的CDK应用程序中向我的API网关添加。但我不确定将其添加到我的API网关实例的何处:

const api = new apiGateway.RestApi(this, "my-api", {..})
..
当我将其部署到AWS时,我确实将端点视为

https://someid123.execute-api.us-east-1.amazonaws.com/prod

我猜这已经启用了TLS(使用
https
)?如果是,我如何查看实际使用的安全策略?

为什么部署API网关,端点的url将具有SSL证书

使用Amazon API网关创建的API仅公开HTTPS端点。API网关不支持未加密(HTTP)端点

您无法控制其策略,并且没有AWS API来获取其详细信息。但是,您可以在连接到API端点后在浏览器中进行检查,例如在Firefox中:


如果您想控制自己的证书,您需要。

REST Api支持TLS 1.2和TLS 1.0,当我们添加自定义域时,我们可以选择传递安全策略。我们无法选择AWS提供的默认端点

securityPolicy:apigw.securityPolicy.TLS_1_2
to
domainName.securityPolicy

const restapi = new apigw.RestApi(this, 'my-rest-api', {
    description: `test`,
    restApiName: `test-api`,
    endpointTypes: [apigw.EndpointType.REGIONAL],
    domainName: {
        securityPolicy: apigw.SecurityPolicy.TLS_1_2,
        domainName: `test-api.mydomain.com`,
        certificate: acm.Certificate.fromCertificateArn(
                      this,'my-cert', myCertArn),
        endpointType: apigw.EndpointType.REGIONAL,
    },
    deployOptions: {
        stageName: 'qa'
    },
});
    const hostedZone = route53.HostedZone.fromLookup(this, 'hosted-zone-lookup', {
        domainName: `mydomain.com`,
    });
    new route53.ARecord(this, 'api-gateway-route53', {
        recordName: `test-api.mydomain.com`,
        zone: hostedZone,
        target: route53.RecordTarget.fromAlias(new route53Targets.ApiGateway(restApi)),
    });

执行上述操作是否也会创建默认url?首先,您可以创建一个RestAPI并注册一个映射到默认url的新域名。我们需要一个自定义域,要在DNS提供程序(例如:Route53)中注册Api网关,我们首先在Api网关上创建一个自定义域,如上所述,然后添加DNS条目以指向此自定义域。这一切都可以在CDK应用程序中完成吗?或者涉及手动步骤。看起来只是从CDK应用程序创建了一个DNS记录。我用CDK代码导入acm更新了答案,并添加了route53 EntryThank。它无法创建证书,我不知道为什么。但如果需要的话,我会提出一个单独的问题。