@codedazur/cdk-essentials
v0.1.0
Published
Maintainers
Keywords
Readme
@codedazur/cdk-essentials
Utilities for AWS CDK that are shared by the other @codedazur/cdk-* packages.
Importing Values Across Regions
importAcrossRegions returns a value of a construct in another region, for use in the stack of the given scope. This is typically needed for CloudFront, which requires its certificates and web ACLs in us-east-1, while the rest of your application is in another region.
const edge = new Stack(app, "Edge", {
env: { account, region: "us-east-1" },
});
const certificate = new Certificate(edge, "Certificate", {
domainName: "example.com",
validation: CertificateValidation.fromDns(),
});
const site = new Stack(app, "Site", {
env: { account, region: "eu-central-1" },
});
const certificateArn = importAcrossRegions(site, {
source: certificate,
name: "CertificateArn",
value: certificate.certificateArn,
});If both stacks are in the same region, it returns the value itself. Otherwise, the source stores the value in an SSM parameter in its own region, and a custom resource in the stack of the scope reads it on every deploy. That stack then depends on the stack of the source, so deploying it deploys the source first. Each value is imported once per stack, and stacks in other regions share the same parameter. The account must be bootstrapped in both regions.
Unlike CDK's crossRegionReferences, this deploys no Lambda functions in the region of the source, which some organizations' policies don't allow.
The Firewall of cdk-firewall and the certificate of a SiteDistribution are imported this way automatically.
