Skip to content

Instantly share code, notes, and snippets.

@badfun
Last active May 27, 2022 21:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save badfun/28287ec0e739f77ea775cc9b2388f82e to your computer and use it in GitHub Desktop.
Save badfun/28287ec0e739f77ea775cc9b2388f82e to your computer and use it in GitHub Desktop.
AWS custom resources in the AWS CDK allow us to achieve functionality that might not be available otherwise. In this case, I needed a secure string parameter to be converted to a string that I could pass directly to a bash script. Any of the other lookups resulted in an error, as it would pass either the token itself or the encrypted string.
import { AwsCustomResource, AwsCustomResourcePolicy, PhysicalResourceId } from '@aws-cdk/custom-resources'
/**
* Secure string from Parameter store
*/
const getParameter = new AwsCustomResource(this, 'SsmSecureStringParameter', {
onUpdate: {
service: 'SSM',
action: 'getParameter',
parameters: {
Name: this.node.tryGetContext('secureStringParameter'),
WithDecryption: true,
},
physicalResourceId: PhysicalResourceId.of(Date.now().toString()),
},
policy: AwsCustomResourcePolicy.fromSdkCalls({
resources: AwsCustomResourcePolicy.ANY_RESOURCE,
}),
})
const secureString = getParameter.getResponseField('Parameter.Value')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment