Skip to content

Commit

Permalink
fix(aws-cdk): fix bug in SSM Parameter Provider (#1023)
Browse files Browse the repository at this point in the history
SSM Parameter Provider Plugin was not properly updated
for the new context provider protocol. It is now,
 and an integ test is added.
  • Loading branch information
rix0rrr authored Oct 26, 2018
1 parent e283711 commit 6e6aa1d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
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);
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

0 comments on commit 6e6aa1d

Please sign in to comment.