-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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] Create certificate in us-east-1 and use it in a different region #9274
Comments
Hi @dbartholomae, You generally have two different options for using a certificate cross-region.
Let me know if that helps! |
Thanks for the answer! It is good to know that DnsValidatedCertificate is able to request cross-region. Unfortunately the domain in question is not managed by Route53. |
If you already have a Certificate created and defined, you can skip the second stack and just import it directly in your Cognito stack. const certificate = acm.Certificate.fromCertificateArn(this, 'MyImportedCert', 'arn:aws:acm:us-east-1:123456789012:certificate/12345678-1234-1234-1234-123...'); If you are creating the certificate in one stack (and validating via email or manually with another DNS provider), then you can pass a reference from one stack to another. Something like this: class MyCertStack extends cdk.Stack {
public readonly certificate: acm.Certificate;
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
super(scope, id, props);
certificate = new acm.Certificate(...);
}
}
interface MyCognitoStackProps extends cdk.StackProps {
certificate: acm.Certificate;
}
class MyCognitoStack extends cdk.Stack {
constructor(scope: cdk.App, id: string, props: MyCognitoStackProps) {
const certificate = props.certificate;
// Define your Cognito pool here, using the above certificate
}
}
const certStack = new MyCertificateStack(app, 'MyCerts');
new MyCognitoStack(app, 'MyCognito', { certificate: certStack.certificate }); |
I'm trying the second solution, but so far I always get a cross-stack reference error because the certificate is in us-east-1, but the other stack in eu-central-1. |
Ah, that's correct. Sorry for the misinformation earlier. Unfortunately, we currently only support cross-environment (region/account) references in instances where we can assign the physical names to the resources; in cases like certificates, where there is only the ARN, we don't currently have a solution. See #8232 (comment) for one work-around suggestion of creating a custom resource to do the heavy lifting for you. It looks like there are various community-owned solutions to this; I found https://www.npmjs.com/package/@henrist/cdk-cross-region-params as one example. I haven't tested this and can't support it, but it looks like it could be used to pass the certificate ARN cross-stack. YMMV. :) |
Thanks! Using SSM is actually quite a smart solution. I'll look deeper into it. |
Did aws cdk added officially support for this? I am also struggling with the same problem. |
@robertofd1995 not sure if are still stuck with this. If you still are, I think you might be looking for create cross region ACM. |
+1 for this feature. I know there are some suggested workaround above, but would be nice to see an easier method to implement this. My scenario is an Edge API in |
Thank you @lenfree, you just saved me hours of headaches 🤗 |
You saved my day ❤️ |
Using cross-region certificate, HostedZone is a required attribute. For our purposes, we have our HostedZone in another AWS account so using this method will not work. This seems like an odd limitation as I can create a certificate in another region through the AWS console. |
The "acm.DnsValidatedCertificate" is now deprecated. Is there any movement so we can create cross-region certificate using "acm.Certificate"? |
I'm also struggling with this. I'm trying to deploy a S3/CloudFront stack in us-west-2 with a certificate that was created in another stack in us-east-1. Short of writing a custom resource lambda to go hunt for the certificate and put its info into SSM Parameter Store, what is the best way to accomplish this? |
The problem becomes a real nightmare when using a custom domain for Cognito UserPool. The UserPool CustomDomain needs an ICertificate, not a Certificate ARN. So there is no solution besides DnsValidatedCertificate which is deprecated. This issue should not be closed! |
Yeah this is going to become a real problem using certs for Cloudfront too. |
Why has |
y I just came across the same problem. I believe one option to solve this is to create the certificate in a separate stack (with env.region: us-east-1). Then reference the certificate in the other stack and use lookup. Don't know if there is a better way. |
Is there a function for lookup in Certificate construct? there is |
I had to write everything in the same app. Defining the two stacks in the same file.
|
We now also have a lot of refactoring to do as it appears that the deprecated construct will no longer create the resources defined in our stacks. If one of the certificates gets deleted, we're currently unable to just re-deploy to replace it. Not best pleased. |
Hello, I've successfully implemented a cross-region deployment, positioning the S3-Cloudfront stack in Europe and the certificate in the us-east-1 region. I've detailed my approach in a blog post. https://medium.com/@mhkafadar/a-practical-aws-cdk-walkthrough-deploying-multiple-websites-to-s3-and-cloudfront-7caaabc9c327 |
This is now documented in https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_certificatemanager-readme.html#cross-region-certificates. |
This is quite an annoying pitfall that everyone gets into when using CloudFront with ACM and not deploying resources in us-east-1. |
this is just downrigth awful.. |
Thanks @JavierMendozaGomez and @epiphone
|
Unfortunately having a cross-stack reference has the limitation of having to hard-code the zone for all other stacks in the app because
|
be sure to upvote this or thumbs up it or mark it as an answer so others know it works ... only if it works for you of course ... this way we can save others weeks of trying to figure this out I have finally figured out how to actually do this ... i am using cdk 2.128.0 This actually works because i am in ca-central-1 and i was able to do it in one stack and created a us-east-1 cert you can checkout the github code here https://github.com/quantfreedom/aws_cdk_testing/blob/main/amazon_cdk/frontend/www.py if that doesn't work here is a gist of the current working version https://gist.github.com/quantfreedom/e71267553edc8e0760e88d48ad8b45a7 I watched this youtube video to get an understanding of what is going on and why i am doing the things i am doing and here is their gh code https://github.com/Durgaprasad-Budhwani/hands-on-aws-cdk-lab/blob/main/ts/cloudfront/lib/cloudfront-stack.ts also here is a link to my github repo where i am just testing out different aws stacks |
This is an example of a really bad experience from with AWS certificate manager. Got over this issue a number of times which might have costed us AWS developers hundred of hours. Ended up creating the certificate manually via CLI/console and use the ARN to reference it. |
Hi, I am reopening this issue as a feature request as we've seen the concerns still outstanding. Let me clarify this and we welcome any further thoughts to make the CDK experience even better. Major complaints about current experience
Thank you for raising this important concern about cross-region certificate management. We understand this has been a pain point for many of our customers, and we appreciate the detailed feedback. Current Recommended SolutionFor cross-region certificate usage (such as with CloudFront and Cognito), we currently recommend using a multi-stack deployment pattern with the const stack1 = new Stack(app, 'CertStack', {
env: { region: 'us-east-1' }, // Certificate must be in us-east-1 for CloudFront
crossRegionReferences: true
});
const cert = new acm.Certificate(stack1, 'Cert', {
domainName: '*.example.com',
validation: acm.CertificateValidation.fromDns()
});
const stack2 = new Stack(app, 'DistributionStack', {
env: { region: 'us-east-2' }, // Your app can be in any region
crossRegionReferences: true
});
// Reference the certificate from stack1 in stack2
new cloudfront.Distribution(stack2, 'Distribution', {
defaultBehavior: { origin: new origins.HttpOrigin('example.com') },
domainNames: ['dev.example.com'],
certificate: cert
}); The reason you need to specify the Important Notes
Moving ForwardWe understand that the current solution might not cover all use cases perfectly, and we're actively working on improvements. Your feedback helps us prioritize enhancements to the CDK's certificate management capabilities. If you encounter specific issues with this approach or have additional use cases not covered by the current solution, please let us know. We're committed to improving the developer experience and making cross-region certificate management more straightforward. Additional ResourcesAlso, as this thread has been very lengthy and could be very difficult to help users focus on the latest solution. If you are still having any issue or feature request around this use case, please kindly create a new issue. We will be happy to look into your case or any new idea about the API design. Please don't hesitate to provide additional feedback or ask for clarification. We're here to help! |
@pahud do this cross stack reference work if there requirement of replacement of ACM? e.g. domain name expanded and added a new subdomain. using i don't see how cross stack reference can handle this well Also do the CDK team had chatted with Cfn team regarding implementing it officially? aws-cloudformation/cloudformation-coverage-roadmap#523 |
Thank you for sharing your use case. I think before CFN has native cross-region support, any workaround in CDK would never have the best developer experience. I see 120 upvotes on aws-cloudformation/cloudformation-coverage-roadmap#523 and I believe CFN team definitely would consider that but I can't see any further details from there. Yes, I'd submit an internal ticket to CFN team about this for better visibility but I can't guarantee any timelines about its ETA of that CFN support. I'll add internal ticket reference here and I'll update here as soon as I have any news I can share. Meanwhile, please help us click 👍 on this issue(not this comment). I am seeing 10 upvotes now. Having more upvotes would definitely help the team prioritize. Thank you. |
internal tracking - V1660274068 |
❓ General Issue
The Question
I'm currently setting up AWS Cognito with a custom domain via AWS CDK. Our stack lives in eu-central-1, but as I understand the certificate for the custom domain has to live in us-east-1. How can I share the certificate to the AWS Cognito setup?
Environment
Other information
There's a discussion around this already which indicates there might not be a solution to this?
The text was updated successfully, but these errors were encountered: