- Più recenti
- Maggior numero di voti
- Maggior numero di commenti
CDK has a Fn.importValue
method you can use to access exported values: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.Fn.html - it should help if the stack that has the exported value exists and is in the same region as your calling stack.
Yes, I mentioned in my first reply that importValue requires
the stack that has the exported value exists and is in the same region as your calling stack
If the stack hasn't been created the outputs won't exist.
It may be possible to pass the value of api.url
directly if this is all in one CDK app, by creating stack properties that you pass to the stack that requires them, but I don't know from the info you've given if api.url
will be synthesised at that point.
It may be (again, hard to know without seeing all your code) that the solution you have arrived at is the only one that will work in your case, as you can only access the exported value after the stack that exports it has been created.
Have you tried the following?
import * as cdk from 'aws-cdk-lib';
// build action
const integtestBuildAction = new aws_codepipeline_actions.CodeBuildAction({
environmentVariables: {
SERVICE_URL: {
value: cdk.Fn.importValue('Url'),
},
},
Error because the importValue("Url") is not existed yet. When we writing the pipeline, none stacks deployed yet, so the Url is not existed. We need to access the Url at runtime instead. My work around is that, in the BuildAction I run a query to find the output Url. However, this is not convenient.
`SERVICE_URL=$(aws cloudformation describe-stacks --stack-name PreProdApplicationStack --query "Stacks[0].Outputs[?OutputKey=='UrlPreProd'].OutputValue" --output text)`
Contenuto pertinente
- AWS UFFICIALEAggiornata 2 anni fa
- AWS UFFICIALEAggiornata 3 anni fa
- AWS UFFICIALEAggiornata un anno fa
Thank you, I understand the cross-stack reference. But I wanted to pass a stack outputs to a CodeBuild action as an environment variable. For example, I want to pass API URL after deployment for some integration test in CodeBuild.