Skip to content

Instantly share code, notes, and snippets.

@jewelsjacobs
Created August 2, 2019 16:28
Show Gist options
  • Select an option

  • Save jewelsjacobs/2b1e8cb55a191f5b75b267456f0e812f to your computer and use it in GitHub Desktop.

Select an option

Save jewelsjacobs/2b1e8cb55a191f5b75b267456f0e812f to your computer and use it in GitHub Desktop.
SSMPutParameter Custom Construct
import cfn = require('@aws-cdk/aws-cloudformation');
import lambda = require('@aws-cdk/aws-lambda');
import cdk = require('@aws-cdk/core');
import path = require('path');
import iam = require('@aws-cdk/aws-iam');
export interface SSMPutParameterProps {
Name: string;
Value: string;
}
export class SSMPutParameter extends cdk.Construct {
public readonly response: string;
constructor(parent: cdk.Stack, name: string, props: SecretsProps) {
super(parent, name);
const putParamsLambda = new lambda.SingletonFunction(this, 'Singleton', {
uuid: 'f7d4f730-4ee1-11e8-9c2d-fa7ae01bbebc',
code: lambda.Code.asset(path.join(__dirname, 'lambda')),
handler: 'index.handler',
timeout: cdk.Duration.seconds(300),
runtime: lambda.Runtime.NODEJS_10_X,
})
const putParamsLambdaPolicy = new iam.PolicyStatement({
actions: ["ecr:GetAuthorizationToken",
"cloudwatch:PutMetricData",
"ds:CreateComputer",
"ds:DescribeDirectories",
"ec2:DescribeInstanceStatus",
"logs:*",
"ssm:*",
"ec2messages:*"],
resources: ["*"]}
);
putParamsLambda.addToRolePolicy(putParamsLambdaPolicy)
const resource = new cfn.CustomResource(this, 'Resource', {
provider: cfn.CustomResourceProvider.lambda(putParamsLambda),
properties: props
});
this.response = resource.getAtt('Version').toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment