Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws_certificatemanager: new Certificate fails in eu-central-1 #27743

Closed
globus243 opened this issue Oct 29, 2023 · 7 comments
Closed

aws_certificatemanager: new Certificate fails in eu-central-1 #27743

globus243 opened this issue Oct 29, 2023 · 7 comments
Labels
@aws-cdk/aws-certificatemanager Related to Amazon Certificate Manager bug This issue is a bug. effort/medium Medium work item – several days of effort p2

Comments

@globus243
Copy link

Describe the bug

I am deploying a static website hosted in S3 with a CloudFront Distribution, hier ist the relavant part:

 const distribution = new Distribution( this, 'Distribution', {
            defaultBehavior: {
                origin: new S3Origin( siteBucket, {
                    originAccessIdentity: pageOai,
                } ),
                viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
                allowedMethods: AllowedMethods.ALLOW_GET_HEAD_OPTIONS,
                compress: true,
                functionAssociations: [ {
                    eventType: cloudfront.FunctionEventType.VIEWER_REQUEST,
                    function: new cloudfront.Function( this, 'redirectToIndex', {
                        code: cloudfront.FunctionCode.fromInline( `
                            function handler(event) {
                                var request = event.request;
                                if (request.uri !== "/" && (request.uri.endsWith("/") || request.uri.lastIndexOf(".") < request.uri.lastIndexOf("/"))) {
                                    if (request.uri.endsWith("/")) {
                                        request.uri = request.uri.concat("index.html");
                                    } else {
                                        request.uri = request.uri.concat("/index.html");
                                    }
                                }
                                return request;
                            }
                        ` ),
                    } ),
                } ]
            },
            defaultRootObject: "index.html",
            errorResponses: [ {
                httpStatus: 404,
                responseHttpStatus: 404,
                responsePagePath: "/index.html",
                ttl: cdk.Duration.seconds( 0 ),
            } ],
            domainNames: [ siteDomain, "www." + siteDomain ],
            certificate: new aws_certificatemanager.Certificate( this, 'Certificate', {
                domainName: siteDomain,
                subjectAlternativeNames: [ "www." + siteDomain ],
                validation: aws_certificatemanager.CertificateValidation.fromDns( hostedZone ),
            } )
        } )

the deployment into eu-central-1 fails with the following log messages in CloudFormation
image

When I replace the certificate part with the depricated DnsValidatedCertificate:

            certificate: new aws_certificatemanager.DnsValidatedCertificate( this, 'Certificate', {
                domainName: siteDomain,
                hostedZone: hostedZone,
                subjectAlternativeNames: [ "www." + siteDomain ],
                region: 'us-east-1', // Cloudfront only checks this region for certificates.
            } )

it deploys without problems.

I have not tried to deploy this exact stack into other regions.

Expected Behavior

It should create the certificate using my Hosted Zone and create the distribution without problem.

Current Behavior

deployment fails because of what looks like an issue when creating the cert see log: "Content of DNS Record is: null".

Reproduction Steps

create a stack with above distribution and make sure it's deployed to eu-central-1

npm run build
cdk synth
cdk deploy

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.103.1 (build 3bb19ac)

Framework Version

2.103.1 (build 3bb19ac)

Node.js Version

18

OS

Windows

Language

TypeScript

Language Version

TypeScript (5.2.2)

Other information

No response

@globus243 globus243 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 29, 2023
@github-actions github-actions bot added the @aws-cdk/aws-certificatemanager Related to Amazon Certificate Manager label Oct 29, 2023
@pahud
Copy link
Contributor

pahud commented Oct 31, 2023

When you run this in eu-central-1, I think the certificate still has to be in us-east-1.

If not, I guess you will need to first create that in a separate stack in us-east-1 and export the ARN for this stack to import.

certificate: new aws_certificatemanager.Certificate( this, 'Certificate', {
                domainName: siteDomain,
                subjectAlternativeNames: [ "www." + siteDomain ],
                validation: aws_certificatemanager.CertificateValidation.fromDns( hostedZone ),
            } )

@pahud pahud added p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Oct 31, 2023
@globus243
Copy link
Author

you will need to first create that in a separate stack in us-east-1 and export the ARN for this stack to import

Thats what seems to be the solution for this.
Though that does not sound like a customer obessed solution for me: Replacing a working, (for customers) region-agnostic Construct with something that a) requires additional knowledge which is currently not well documented and b) makes deployment of a simple single-page, or static-page application a multi-stack and multi-region endavour.

@globus243 globus243 reopened this Oct 31, 2023
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@globus243
Copy link
Author

sorry, accidentally closed the issue. Problem still persists.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Oct 31, 2023
@gshpychka
Copy link
Contributor

See #25343

@globus243
Copy link
Author

All right, thanks! Since this is clearly not a bug, but desired behavior, I will close this issue.

Copy link

github-actions bot commented Nov 3, 2023

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-certificatemanager Related to Amazon Certificate Manager bug This issue is a bug. effort/medium Medium work item – several days of effort p2
Projects
None yet
Development

No branches or pull requests

3 participants