-
Notifications
You must be signed in to change notification settings - Fork 4k
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
cdk.context.json: vpc lookup which depends on an ssm lookup fails #3654
Comments
Some environment info: CDK CLI Version: |
This is a bug. The CLI has logic to handle dependencies between context provider lookups (it basically repeats synth until all context is resolved). For some reason, this mechanism fails in this instance. |
@eladb I am having the same issue but I have the vpc id hardcoded and not doing any ssm lookups. The issue only exists when there are other constructs that try to use the vpc from lookup and there is no cdk.context.json file. To make it work we have to comment out everything apart from the vpc lookup, run cdk synth which then generates the cdk.context.json file. Then uncomment everything else, it's only then the other constructs can use the vpc from lookup. using cdk 1.4.0 |
The issue is that we return a dummy value for the SSM lookup (instead of aborting execution), which encourages the VPC lookup provider to use the value and error out saying it couldn't find any.
|
The correct solution is for the toolkit not to error out, but propagate the error back to the CDK app which can then attach the error to the construct tree. |
We need that behavior anyway to properly handle context lookups for multiple accounts in the same app. |
Instead of the toolkit failing and stopping when a context provider lookup fails, the error is reported to the CDK app, which can then decide what to do with it. In practice, it will attach a (localized) error to the Construct tree. This has the following advantages: * Dependent context resolution can proceed in a stepwise fashion, without the toolkit stopping at the first failure. For example, a VPC lookup from a value found in SSM will work. * Stacks in multiple accounts that need context lookup can be used in a single app with cold context. Without this change they couldn't, because you could only have credentials for a single account at a time available so lookup for one of the accounts was bound to fail. Fixes #3654.
Does this mean that we shouldn't be using SSM to lookup values of parameters required for synthesis of other stacks? |
Instead of the toolkit failing and stopping when a context provider lookup fails, the error is reported to the CDK app, which can then decide what to do with it. In practice, it will attach a (localized) error to the Construct tree. This has the following advantages: * Dependent context resolution can proceed in a stepwise fashion, without the toolkit stopping at the first failure. For example, a VPC lookup from a value found in SSM will work. * Stacks in multiple accounts that need context lookup can be used in a single app with cold context. Without this change they couldn't, because you could only have credentials for a single account at a time available so lookup for one of the accounts was bound to fail. Fixes #3654.
Instead of the toolkit failing and stopping when a context provider lookup fails, the error is reported to the CDK app, which can then decide what to do with it. In practice, it will attach a (localized) error to the Construct tree. This has the following advantages: * Dependent context resolution can proceed in a stepwise fashion, without the toolkit stopping at the first failure. For example, a VPC lookup from a value found in SSM will work. * Stacks in multiple accounts that need context lookup can be used in a single app with cold context. Without this change they couldn't, because you could only have credentials for a single account at a time available so lookup for one of the accounts was bound to fail. Fixes #3654.
@ccfife Does the CDK pipeline fail at this step? My Java CDK pipeline, when it fails because to assume the lookup role still continues and returns a success result. I was curious if it is just me or maybe I should report it as a bug. This is the output:
|
I'm submitting a ...
What is the current behavior?
If the current behavior is a 🪲bug🪲: Please provide the steps to reproduce
In order to use the pre-existing VPC, as I understand it, I need to use
aws_ec2.Vpc.from_lookup
to find the VPC by an attribute (eg. its ID). For that to work, I need the VPC ID at synth time.To do this, within my stack constructor method, I have:
The problem is that when
cdk synth
is attempted on the above, it fails at the second action (vpc lookup) fails because the vpc ID doesn't already exist in cdk.context.json… the only way to get it written there is to comment out the second and third actions, run cdk synth, which adds the SSM parameter store value to the context. After that, it will succeed on step two, but fail on step 3, because the VPC information is also missing from the context. If I comment out the 3rd action, run cdk synth, then put the 3rd action back, it all works.Something seems wrong here… it seems like the two lookup methods are not behaving idempotently. They should populate context if context is missing, but also always return the looked up value(s), so that this will work whether or not context is already populated. I do have the account and region specified in the stack 'env'.
The text was updated successfully, but these errors were encountered: