如何在 CDK 应用程序中为 API 网关添加安全策略?
How to add security policy to API Gateway in CDK application?
我正在尝试将 TLS 添加到我的 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 将具有 AWS provided SSL 证书。
The APIs created with Amazon API Gateway expose HTTPS endpoints only. API Gateway doesn't support unencrypted (HTTP) endpoints.
您无法控制其政策,没有 AWS API 可以获取其详细信息。但是,您可以在连接到 API 端点后在浏览器中检查它,例如在 Firefox 中:
如果您想控制自己的证书,您需要 own domain。
REST Api 支持 TLS 1.2 和 TLS 1.0 并且当我们添加自定义域时,我们可以选择通过安全策略。我们无法选择 AWS 提供的默认端点。
securityPolicy: apigw.SecurityPolicy.TLS_1_2
到 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)),
});
我正在尝试将 TLS 添加到我的 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 将具有 AWS provided SSL 证书。
The APIs created with Amazon API Gateway expose HTTPS endpoints only. API Gateway doesn't support unencrypted (HTTP) endpoints.
您无法控制其政策,没有 AWS API 可以获取其详细信息。但是,您可以在连接到 API 端点后在浏览器中检查它,例如在 Firefox 中:
如果您想控制自己的证书,您需要 own domain。
REST Api 支持 TLS 1.2 和 TLS 1.0 并且当我们添加自定义域时,我们可以选择通过安全策略。我们无法选择 AWS 提供的默认端点。
securityPolicy: apigw.SecurityPolicy.TLS_1_2
到 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)),
});