-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
(aws-iam): StringParameter.value_from_lookup's dummy value did not suffice #8699
Comments
This is my proposed solution for aws#8699 which also works with resources requiring an ARN. The solution works independently of the parameter value.
@ThomasSteinbach I'm curious to know about the use case that is breaking with this right now. Can you provide details about what constructs/processes you're using that aren't supported currently? |
This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled. |
The dummy return value should probably be a Token, this should suppress literal string validation in most of the CDK. |
Sorry @MrArnoldPalmer for the late response. (I spent my last 14d in holidays). Regarding your questions:
The Reproduction Steps in the issues description will give you one use case ( 'aws_kms.Key` can't handle the current dummy values). Without testing it, in my description I also statet that the solution, provided with this issue ( #8700 ), may resolve #7051 , which then is also a use case, as
As shown in the descriptions example, The proposed solution should work for all other resource methods requiring an ARN, like We've tested workaround (for python) given in the description, and it worked well for us under every circumstances. The proposed solution would fix the issue natively in TypeScript. However a professional TypeScript programmer should review and "cleanup" the solution. |
@ThomasSteinbach thanks, I didn't derive all those details from the original post. Since ssm params can obviously contain stuff other than Arns, and validations may be anything really, a more generic solution is required I believe. As @rix0rrr mentioned, we can possibly change the dummy value return type to be a Token, which makes sense since Tokens are stand ins for values that will resolve at some point in the future. |
As long as it works, I am totally fine with any solution 😃 As Python-CDK user I feel not able to provide a clean solution for replacing the current dummy values by tokens. Could you please provide one or delegate it to a CDK TypeScript programmer? I am confident, that it should be no extravagant expense but would solve this as well as this #7051 issue. Thanks in advance |
Another use case, If putting the json string into SSM parameter store for externalizing the parameters of CDK app, the |
I'm getting this problem when trying to "import" an SNS topic via ARN that I get from parameter store:
Meaning, I can't synthesize this to validate it. This works fine with importing VPCs, ALB listeners, ECS cluster ecs and actually synthesize to the actual parameter store value, so I'm not sure why this becomes a dummy value in this example? EDIT: OH wait, it only fails on first run? If I run the lookup first, then add the |
This actually fails for deploy runs as well, not only synthesizing. Making it somewhat cumbersome to store ARNs on SSM without having to jump through hoops to create the cdk context first without actually using the values. |
and another one: asm.Secret.from_secret_attributes(
scope=scope, id=secret_arn, secret_complete_arn=secret_arn, encryption_key=key
) leads to
CDK: 1.85.0 |
With the following lines of code I am getting a similar error with 1.85.0. Is this a know bug ? If yes will be fixed in the version. Error: jsii.errors.JSIIError: ARNs must start with "arn:" and have at least 6 components: "" |
Hi team! Still planned to be fixed or waiting for better times?) |
I'm trying to load a JSON string from ParameterStore ( |
This is still happening to me using 1.132.0. I'm trying to do a |
The workaround is to check whether the value contains "dummy_value_for*", and replacing it with your own dummy value that adheres to the required pattern. After the first synth, the looked-up value will be written to cdk.context.json and subsequent synths will work as expected. |
That's essentially a hard coding, imho.
After that, we still have to add in a ternary or something to account for the problematic The workaround does work but I'm looking forward to that feature that "fixes" this one 👍 |
I ran into this too, and found a bit more elegant solution recently, which was to use Lazy values. import * as cdk from '@aws-cdk/core';
import * as ssm from '@aws-cdk/aws-ssm';
import * as iam from '@aws-cdk/aws-iam';
const roleArn = ssm.StringParameter.valueFromLookup(this, "/param/testRoleArn");
const role = iam.Role.fromRoleArn(this, "role", cdk.Lazy.string({ produce: () => roleArn })); It's more general because it can apply to many other use cases besides The following is an example that shows why I don't think making When importing a VPC using import * as cdk from '@aws-cdk/core';
import * as ssm from '@aws-cdk/aws-ssm';
import * as ec2 from '@aws-cdk/aws-ec2';
const vpcId = ssm.StringParameter.valueFromLookup(this, "/param/vpcId");
const vpc = ec2.Vpc.fromLookup(this, "vpc", {
vpcId: vpcId
}); This is because However, this method demands your input You can store any kind of strings, for different purposes in a SSM parameter, Seems to me at the moment the best way is to understand your use case and have a look at the source code of the method Anyone interested can have a look at my complete analysis. |
@sdhuang32 thanks for this approach, this is very helpful. Although I often use |
any update on this issue? |
I suffered this issue when synthesizing cdk application in ec2 with IAM role(using Synthesizing same app in local env using AK/SK works, then updated the |
…mats (#21520) `StringParameter.valueFromLookup` can be used to retrieve a string value, but that value could be in any format and there are times where it is provided as input to properties that require a specific format (i.e. arn format). Because of the way that lookups are resolved, it is possible for the initial value to be the dummy value `dummy-value-for-${parameterName}` which might cause synth errors. Since there is no way for the CDK to know _how_ you will use the returned value, we can't really add logic to specifically handle edge cases. For example, we could have `valueFromLookup` always return a token, but then it would no longer be able to be used in cases where a `string` is required. See #8699 (comment) for a good analysis. This PR adds documentation instructing users how to handle these use cases. closes #8699, #9138 ---- ### All Submissions: * [ ] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
|
…mats (aws#21520) `StringParameter.valueFromLookup` can be used to retrieve a string value, but that value could be in any format and there are times where it is provided as input to properties that require a specific format (i.e. arn format). Because of the way that lookups are resolved, it is possible for the initial value to be the dummy value `dummy-value-for-${parameterName}` which might cause synth errors. Since there is no way for the CDK to know _how_ you will use the returned value, we can't really add logic to specifically handle edge cases. For example, we could have `valueFromLookup` always return a token, but then it would no longer be able to be used in cases where a `string` is required. See aws#8699 (comment) for a good analysis. This PR adds documentation instructing users how to handle these use cases. closes aws#8699, aws#9138 ---- ### All Submissions: * [ ] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
returns a
dummy-value-for-${parameterName}
during synthesis (from #3654). This value did not suffice for use as ARN. The dummy value itself should represent a dummy ARN pattern to avoid errors.Reproduction Steps
Here is a short (and stripped) example, which currently leads to an error:
Error Log
During synthesis this leads to an error:
Workaround
Solution Proposal
Instead of
dummy-value-for-${parameterName}
the method should return something likearn:aws:service:eu-central-1:123456789012:entity/dummy-value
This solution would also address/solve #7051
This is 🐛 Bug Report
The text was updated successfully, but these errors were encountered: