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: Improve error message in SSMParameterProvider #1630

Merged
merged 2 commits into from
Jan 29, 2019
Merged
Changes from 1 commit
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
15 changes: 11 additions & 4 deletions packages/aws-cdk/lib/context-providers/ssm-parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,17 @@ export class SSMContextProviderPlugin implements ContextProviderPlugin {
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 available in account ${account}, region ${region}: ${parameterName}`);
try {
const response = await ssm.getParameter({ Name: parameterName }).promise();
if (!response.Parameter || response.Parameter.Value === undefined) {
throw new Error(`SSM parameter not available in account ${account}, region ${region}: ${parameterName}`);
}
return response.Parameter.Value;
} catch (e) {
if (e.code === 'ParameterNotFound') {
throw new Error(`No SSM Parameter named '${parameterName}' was found in ${account}/${region}`);
}
throw e;
}
return response.Parameter.Value;
}
}