-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Description
My feature request is that it is useful to be able to return a configured default value from StringParameter.valueFromLookup() instead of dummy-value-for-parameterName.
Use Case
CDK can lookup ssm parameters like this:
const value:string = ssm.StringParameter.valueFromLookup(this, 'keyName');
It usually works well. However, the returned value may be like dummy-value-for-keyName when no context value exist. In this case, if the returned value is used by some other functions like Bucket.fromBucketArn, Topic.fromTopicArn, or etc, it causes an error like this:
ARNs must have at least 6 components: dummy-value-for-keyName
It prevents from working cdk command well.
Based on the above case, I think it is useful to be able to configure the default value or it is good to return the actual ssm parameter value instead of a dummy value.
Other
The testcase to reproduce this issue is like this:
- Init cdk app.
mkdir foo
cd foo
cdk init sample-app --language=typescript
- Configure a default region and account.
Set env in bin/foo.ts
#!/usr/bin/env node
import * as cdk from '@aws-cdk/core';
import { FooStack } from '../lib/foo-stack';
const myEnv = { account: 'aws account', region: 'a region'};
const app = new cdk.App();
new FooStack(app, 'FooStack', { env: myEnv });
- And then edit lib/foo-stack.ts like this.
import * as cdk from '@aws-cdk/core';
import * as ssm from '@aws-cdk/aws-ssm';
import * as s3 from '@aws-cdk/aws-s3';
export class FooStack extends cdk.Stack {
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const arnValue:string = ssm.StringParameter.valueFromLookup(this, 'keyName');
const bucket = s3.Bucket.fromBucketArn(this, 'FooBucket', arnValue);
}
}
- Then run cdk synth, the application failed even though keyName exists.
$ cdk synth
ARNs must have at least 6 components: dummy-value-for-keyName
Subprocess exited with error 1
I tested it with cdk 1.31.0 .
The workaround of this issue is to comment out fromXxxxArn code in the above step3 to avoid the error of parsing the returned parameter(arnValue). After cdk synth command finish successfully, cdk.context.json is set. So, cdk synth command can success after uncomment the code because the context value is returned instead of a dummy value.
However, the issue reproduces again if you run cdk context --clear true .
This may be similar to #3654 though the issue was closed.
And I think dummy-value-for relates to the following code:
https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/aws-ssm/lib/parameter.ts#L367
- 👋 I may be able to implement this feature request
-
⚠️ This feature might incur a breaking change
This is a 🚀 Feature Request