Skip to content
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

fix(aws-cdk): fix bug in SSM Parameter Provider #1023

Merged
merged 1 commit into from
Oct 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/aws-cdk/integ-tests/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ class MyStack extends cdk.Stack {
constructor(parent, id) {
super(parent, id);
new sns.Topic(this, 'topic');

console.log(new cdk.AvailabilityZoneProvider(this).availabilityZones);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should assert against the resulting value somehow

console.log(new cdk.SSMParameterProvider(this, { parameterName: '/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2' }).parameterValue(''));
}
}

Expand All @@ -21,4 +24,4 @@ const app = new cdk.App();
new MyStack(app, 'cdk-toolkit-integration-test-1');
new YourStack(app, 'cdk-toolkit-integration-test-2');

app.run();
app.run();
6 changes: 3 additions & 3 deletions packages/aws-cdk/lib/contextplugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ export class SSMContextProviderPlugin implements ContextProviderPlugin {
public async getValue(args: {[key: string]: any}) {
const region = args.region;
const account = args.account;
if (!('parameterName' in args.props)) {
if (!('parameterName' in args)) {
throw new Error('parameterName must be provided in props for SSMContextProviderPlugin');
}
const parameterName = args.props.parameterName;
const parameterName = args.parameterName;
debug(`Reading SSM parameter ${account}:${region}:${parameterName}`);

const ssm = await this.aws.ssm(account, region, Mode.ForReading);
const response = await ssm.getParameter({ Name: parameterName }).promise();
if (!response.Parameter || response.Parameter.Value === undefined) {
throw new Error(`SSM parameter not availble in account ${account}, region ${region}: ${parameterName}`);
throw new Error(`SSM parameter not available in account ${account}, region ${region}: ${parameterName}`);
}
return response.Parameter.Value;
}
Expand Down