AWS CDK,为 Route53 中的现有 S3 存储桶创建别名记录
AWS CDK, creating an alias record for an existing S3 bucket in Route53
我想知道如何获取现有的 S3 存储桶并使用 AWS CDK 创建指向它的别名记录点?
到目前为止一切顺利:
const myExistingBucket = Bucket.fromBucketName(this, 'myExistingBucket', 'myExistingBucketName')
new route53.ARecord(this, 'myAliasRecord', {
zone: myHostedZone,
target: route53.AddressRecordTarget.fromAlias(new route53_targets.BucketWebsiteTarget(myExistingBucket))
});
我得到:'IBucket' 类型的参数不可分配给 'Bucket'.
类型的参数
fromBucketArn()
、fromBucketAttributes()
和 fromBucketName()
函数都是 return IBucket
类型,但是 BucketWebsiteTarget()
函数需要一个 Bucket
类型。
那么,我应该如何使用 AWS CDK 从现有类型中获取 Bucket
类型?
最后,基于AWS CDK Static Site Example,我最终使用 CloudFront 通过 S3 Bucket 提供 HTTPS(这是一种更好的做法)。 s3BucketSource
直接接受 IBucket
类型。
const myExistingBucket = Bucket.fromBucketName(this, 'myExistingBucket', 'myExistingBucketName')
// CloudFront distribution that provides HTTPS
const devDistribution = new cloudfront.CloudFrontWebDistribution(this, 'mySiteDistribution', {
aliasConfiguration: {
acmCertRef: certArn, // Must be in us-east-1 region.
names: ['app.example.com'],
sslMethod: cloudfront.SSLMethod.SNI,
securityPolicy: cloudfront.SecurityPolicyProtocol.TLS_V1_1_2016,
},
originConfigs: [
{
s3OriginSource: {
s3BucketSource: myExistingBucket
},
behaviors: [{ isDefaultBehavior: true }],
}
]
});
new route53.ARecord(this, 'myAliasRecord', {
zone: zone,
target: route53.AddressRecordTarget.fromAlias(new route53_targets.CloudFrontTarget(devDistribution)),
});
我想知道如何获取现有的 S3 存储桶并使用 AWS CDK 创建指向它的别名记录点?
到目前为止一切顺利:
const myExistingBucket = Bucket.fromBucketName(this, 'myExistingBucket', 'myExistingBucketName')
new route53.ARecord(this, 'myAliasRecord', {
zone: myHostedZone,
target: route53.AddressRecordTarget.fromAlias(new route53_targets.BucketWebsiteTarget(myExistingBucket))
});
我得到:'IBucket' 类型的参数不可分配给 'Bucket'.
类型的参数fromBucketArn()
、fromBucketAttributes()
和 fromBucketName()
函数都是 return IBucket
类型,但是 BucketWebsiteTarget()
函数需要一个 Bucket
类型。
那么,我应该如何使用 AWS CDK 从现有类型中获取 Bucket
类型?
最后,基于AWS CDK Static Site Example,我最终使用 CloudFront 通过 S3 Bucket 提供 HTTPS(这是一种更好的做法)。 s3BucketSource
直接接受 IBucket
类型。
const myExistingBucket = Bucket.fromBucketName(this, 'myExistingBucket', 'myExistingBucketName')
// CloudFront distribution that provides HTTPS
const devDistribution = new cloudfront.CloudFrontWebDistribution(this, 'mySiteDistribution', {
aliasConfiguration: {
acmCertRef: certArn, // Must be in us-east-1 region.
names: ['app.example.com'],
sslMethod: cloudfront.SSLMethod.SNI,
securityPolicy: cloudfront.SecurityPolicyProtocol.TLS_V1_1_2016,
},
originConfigs: [
{
s3OriginSource: {
s3BucketSource: myExistingBucket
},
behaviors: [{ isDefaultBehavior: true }],
}
]
});
new route53.ARecord(this, 'myAliasRecord', {
zone: zone,
target: route53.AddressRecordTarget.fromAlias(new route53_targets.CloudFrontTarget(devDistribution)),
});