Skip to content

Instantly share code, notes, and snippets.

@JelsB
Created January 10, 2021 16:37
Show Gist options
  • Save JelsB/efe2b1b31b88b52dba9eb7955e87edc1 to your computer and use it in GitHub Desktop.
Save JelsB/efe2b1b31b88b52dba9eb7955e87edc1 to your computer and use it in GitHub Desktop.
export class SSMParameterReader extends AwsCustomResource {
constructor(scope: Construct, name: string, props: SSMParameterReaderProps) {
const { parameterName, region } = props
const ssmAwsSdkCall: AwsSdkCall = {
service: 'SSM',
action: 'getParameter',
parameters: {
Name: parameterName
},
region,
physicalResourceId: { id: Date.now().toString() } // Update physical id to always fetch the latest version
}
super(scope, name, {
onUpdate: ssmAwsSdkCall,
policy: AwsCustomResourcePolicy.fromStatements([
new iam.PolicyStatement({
resources: ['*'],
actions: ['ssm:GetParameter'],
effect: iam.Effect.ALLOW
})
])
}
)
}
public getParameterValue(): string {
return this.getResponseField('Parameter.Value')
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment