我想知道如何使用AWS CDK获取现有的S3存储桶并为其创建别名记录点吗?
到目前为止很好:
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()
函数都返回IBucket
类型,但是BucketWebsiteTarget()
函数需要Bucket
类型。
那么,我应该如何使用AWS CDK从现有类型中获取Bucket
类型?
答案 0 :(得分:1)
最后,我最终使用CloudFront基于AWS CDK Static Site Example在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)),
});