parislyons
parislyons

Reputation: 1

How can I pass AWS construct information to a container build with CDK?

I'm building the IaC for my containerised Vite/React project to deployed to AWS but the issue I've run into is that I can't pass info to my buildargs for the container, which I need to overwrite values in my .env file for the vite build.

The approach I took was to use a Cfn export to which would then be put into the buildargs for the DockerImageAsset, then the arg written to an env in the Dockerfile and an sed command would print it to the .env before build. I've managed to get this working for the cognito variables such as the Cognito domain since they're predictably named, but the DNS for the load balancer on the backend and Cognito App Client ID and Userpool ID can't be propagated as CDK synth gives an error that tells me that I can't use a token for a key in a buildarg as it needs the build info before the deployment.

The Cognito Userpool and App Client are in a separate stack that is synthed/deployed first but that seems to not matter as any cdk synth will fail, even when using the --exclusively flag.

Is there a different approach that would work or am I just not doing the current method correctly?

Upvotes: 0

Views: 74

Answers (1)

Marcelo Luiz Onhate
Marcelo Luiz Onhate

Reputation: 521

if you are creating CfnOutput on the first stack deployed you can run read the outputs of the stack from the cdk.out folder, something like

cat cdk.out/outputs.json

and it will print a json with a structure similar to

{
  "<stack-name>": {
     "<outputname>": "<outputvalue>"
  }
}

Upvotes: 0

Related Questions