Get RDS proxy endpoint to a cross account stack #13683
-
Is there a good way to get a proxy endpoint to a cross account stack? import * as cdk from "@aws-cdk/core";
import * as rds from "@aws-cdk/aws-rds";
import * as ec2 from "@aws-cdk/aws-ec2";
import * as lambda from "@aws-cdk/aws-lambda";
import { PhysicalName } from "@aws-cdk/core";
const app = new cdk.App();
const stack1 = new cdk.Stack(app, "Stack1", {
env: { account: "111111111", region: "us-east-1" },
});
const vpc = new ec2.Vpc(stack1, "Vpc");
const cluster = new rds.DatabaseCluster(stack1, "Database", {
engine: rds.DatabaseClusterEngine.auroraMysql({
version: rds.AuroraMysqlEngineVersion.VER_2_08_1,
}),
credentials: rds.Credentials.fromGeneratedSecret("clusteradmin"), // Optional - will default to 'admin' username and generated password
instanceProps: { vpc },
});
const proxy = cluster.addProxy("Proxy", {
dbProxyName: PhysicalName.GENERATE_IF_NEEDED,
vpc,
secrets: [cluster.secret!],
});
const stack2 = new cdk.Stack(app, "Stack2", {
env: { account: "222222222", region: "us-west-2" },
});
new lambda.Function(stack2, "MyLayeredLambda", {
code: new lambda.InlineCode("foo"),
handler: "index.handler",
runtime: lambda.Runtime.NODEJS_10_X,
environment: {
PROXY_ENDPOINT: proxy.endpoint,
},
}); Results in
This makes total sense, but I'm curious if there's a workaround, or a better way to do this? ☝️ well, that idea doesn't work either |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
There's a helpful solution described here that can help you create a cross-region reference https://stackoverflow.com/questions/59774627/cloudformation-cross-region-reference in v2 you can simply enable this prop on your stack https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.Stack.html#crossregionreferences |
Beta Was this translation helpful? Give feedback.
-
Hello! Reopening this discussion to make it searchable. |
Beta Was this translation helpful? Give feedback.
There's a helpful solution described here that can help you create a cross-region reference https://stackoverflow.com/questions/59774627/cloudformation-cross-region-reference
in v2 you can simply enable this prop on your stack https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.Stack.html#crossregionreferences