- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
对于这个问题,假设我已经有一个 example.org
Route53 中的托管区域(我的实际区域当然不同)
使用以下 CDK 应用程序:
export class MyExampleStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const backend = new Function(this, 'backendLambda', {
code: new AssetCode("lambda/"),
handler: "index.handler",
runtime: Runtime.PYTHON_3_8
});
apiDomainName = 'api.test.example.org'
const api = new LambdaRestApi(this, 'api', {
handler: backend,
proxy: true,
deploy: true,
domainName: {
domainName: apiDomainName,
certificate: new Certificate(this, 'apiCertificate', {
domainName: apiDomainName
})
}
});
}
}
,当我运行
cdk deploy
,部分输出内容如下:
Outputs:
MyExampleStack.apiEndpoint0F54D2EA = https://<alphanumericId>.execute-api.us-east-1.amazonaws.com/prod/
,事实上,当我
curl
那个 url,我看到了我期望从我的 Lambda 代码中得到的响应。我希望
curl
学习
api.test.example.org
给出相同的结果 - 但是,它给出了
curl: (6) Could not resolve host: api.test.example.org
.
export class MyExampleStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const rootDomain = 'example.org'
const zone = HostedZone.fromLookup(this, 'baseZone', {
domainName: rootDomain
});
const backend = new Function(...);
const api = new LambdaRestApi(...);
new ARecord(this, 'apiDNS', {
zone: zone,
recordName: 'api.test',
target: RecordTarget.fromAlias(new ApiGateway(api))
});
}
}
这确实给出了一个 Route53 条目:
$ aws route53 list-hosted-zones
{
"HostedZones": [
{
"Id": "/hostedzone/ZO3B2N6W70PDD",
"Name": "example.org.",
"CallerReference": "598D71AB-4A98-EC5A-A170-D51CB243A2EA",
"Config": {
"PrivateZone": false
},
"ResourceRecordSetCount": 8
}
]
}
$ aws route53 list-resource-record-sets --hosted-zone-id /hostedzone/ZO3B2N6W70PDD --query 'ResourceRecordSets[?Name==`api.test.example.org.`]'
[
{
"Name": "api.test.example.org.",
"Type": "A",
"AliasTarget": {
"HostedZoneId": "Z1UJRXOUMOOFQ9",
"DNSName": "<alphanumericId2>.execute-api.us-east-1.amazonaws.com.",
"EvaluateTargetHealth": false
}
}
]
但这仍然不起作用:
curl api.test.example.org
仍然给出“无法解析主机”curl <alphanumericId2>.execute-api.us-east-1.amazonaws.com
给 curl: (7) Failed to connect to <alphanumericId2>.execute-api.us-east-1.amazonaws.com port 80: Connection refused
curl https://<alphanumericId2>..execute-api.us-east-1.amazonaws.com
给 {"message":"Forbidden"}
curl https://<alphanumericId>.[...]
(即 cdk deploy
的输出)仍然给出来自 Lambda 最佳答案
带有 Route53 A Record 的总体代码 LambdaRestApi 将创建
prod
即api.test.example.org
域到阶段“产品”(示例)api.test.example.org
的记录指向 Api Gateway 托管区域。 https://abcdef1234.execute-api.us-east-1.amazonaws.com/prod/
将在附加阶段时工作。 import * as cdk from "@aws-cdk/core";
import * as apigw from "@aws-cdk/aws-apigateway";
import * as acm from "@aws-cdk/aws-certificatemanager";
import * as route53 from "@aws-cdk/aws-route53";
import * as route53Targets from "@aws-cdk/aws-route53-targets";
import * as lambda from "@aws-cdk/aws-lambda";
export class HelloCdkStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
this.buildLambdaApiGateway();
}
buildLambdaApiGateway() {
const rootDomain = "example.org";
const zone = route53.HostedZone.fromLookup(this, "baseZone", {
domainName: rootDomain,
});
const backend = new lambda.Function(this, "MyLayeredLambda", {
code: new lambda.InlineCode("foo"),
handler: "index.handler",
runtime: lambda.Runtime.NODEJS_10_X,
});
const restApi = new apigw.LambdaRestApi(this, "myapi", {
handler: backend,
domainName: {
domainName: `api-test.${rootDomain}`,
certificate: acm.Certificate.fromCertificateArn(
this,
"my-cert",
"arn:aws:acm:us-east-1:111112222333:certificate/abcd6805-1234-4159-ac38-761acdc700ef"
),
endpointType: apigw.EndpointType.REGIONAL,
},
});
new route53.ARecord(this, "apiDNS", {
zone: zone,
recordName: "api-test",
target: route53.RecordTarget.fromAlias(
new route53Targets.ApiGateway(restApi)
),
});
}
}
关于amazon-web-services - 如何在 CDK 中为基于 Lambda 的 APIGateway 提供自定义域名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65986897/
我正在尝试引用几个子网来创建 ec2 实例,但我有点卡住了。 假设我有这个: const vpc = new Vpc(this, 'gwc-vpc', { cidr: "10.20.
我们正在使用 AWS CDK 来创建我们的无服务器 REST API。但是,有大量端点,有时我们必须销毁和重新部署我们的堆栈。为了防止 REST API URL 随每次部署而更改,我计划在一个堆栈中创
我看到了各种使用 AWS CDK 的示例,其中一些使用 aws-cdk-lib,另一些使用 @aws-cdk/core。这些之间有什么区别,什么时候应该使用一个或另一个? 最佳答案 aws-cdk-l
我看到了各种使用 AWS CDK 的示例,其中一些使用 aws-cdk-lib,另一些使用 @aws-cdk/core。这些之间有什么区别,什么时候应该使用一个或另一个? 最佳答案 aws-cdk-l
我是 CDK 的新手,需要了解高级构造与低级构造之间的区别。谁能用简单的话解释一下:) 热烈的问候。 最佳答案 CDK 旨在让任何人都能轻松创建具有预配置默认值的组件。这意味着您可以(使用更高级别的构
我不想使用我的默认 aws 配置文件和帐户进行 cdk 开发 所以我创建了一个新帐户和一个新的个人资料 cdkprof使用 aws configure --profile cdkprof . 我已经在
我有一个在 cdk.context.json 中存储一些键值的用例,但是如果 cdk.context.json 不存在或者它不包含我希望 CDK 回退到其他代码来发现的键值(value)。 例如,假设
我创建了一个将部署在多个区域的 CDK 堆栈。其中一种构造只能部署在一个地区。在 Cloudformation 中,我只是向资源添加一个条件,但我还没有找到一种方法来对 CDK 构造做类似的事情。 可
以下CDK代码 const queue = new sqs.Queue(this, 'my-sqs-queue', { visibilityTimeout: cdk.Duratio
Use an AWS CloudFormation Parameter AWS CDK 的部分提到了如何自定义您的 AWS CloudFormation 模板。指的是云形成模板 .我想将参数添加到我的
@aws-cdk/pipelines 的文档似乎表明可以使用 codePipeline Prop 将 CDK 管道添加到现有的@aws-cdk/aws-codepipeline/Pipeline:ht
我遇到了一个问题,我们想要确保在 CloudFormation 资源的命名中遵循一些约定。这个想法是我们使用 CDK Aspects来处理资源。一个简单的例子: export class Bucket
我正在寻找一种方法来指定我的项目中堆栈的部署顺序。 我知道我可以添加依赖项,但是这些堆栈不相互依赖,我可能想稍后删除一些。 我有一个服务框架,每个其他堆栈(例如 rds)都需要这些服务框架。这些都是在
是否可以使用 AWS CDK CLI 以某种方式获取另一个堆栈所依赖的堆栈列表?例如,给定一个类似于以下内容的堆栈列表: const app = new App(); const alphaStack
我正在使用 CDK Python API 定义 Glue 爬虫,但是,CDK 生成的模板在爬虫资源中包含空的“目标” block 。 我一直没能找到一个例子来模仿。我试过改变目标对象的定义,但对象定义
我们正在开发一个多账户 CDK 应用程序,并在 CodeBuild 上进行持续部署。我们知道 CDK authentication issues所以我们使用 $ aws sts assume-role
aws-cdk 允许您合成一个堆栈 - 这会产生许多文件 - 包括 .template.json 文件。 可以在没有 aws-cdk 工具的情况下部署这个 .template.json 文件吗?还是设
是否可以使用 aws-cdk 部署到 localstack? 想过从无服务器切换到 cdk,但除了 aws SAM 之外找不到任何其他本地测试选项。 最佳答案 我现在正在应对同样的挑战。我得到的方法是
我的 CDK 堆栈包含太多参数(子网 ID、API URL),无法在命令行中指定。所以我想将它们保存在单独的文件中,例如 dev.properties 或 prod.json。来自 cdk.json
我的 CDK 堆栈包含太多参数(子网 ID、API URL),无法在命令行中指定。所以我想将它们保存在单独的文件中,例如 dev.properties 或 prod.json。来自 cdk.json
我是一名优秀的程序员,十分优秀!