AWS CDK: Store data in AWS Parameter Store

February 11th, 2020 132 Words

When you orchestrate an architecture von AWS, you’ll often end up with the need to store information like hostnames, identifiers, resource names or ARNs somewhere for further processing. CloudFormation Stacks can have configured Outputs, but using the AWS Parameter Store proved to be a more flexible solution. Using the AWS Cloud Development Kit in TypeScript, you can easily store data like an S3 Bucket domain name in AWS Parameter Store.

import * as CDK from "@aws-cdk/core";
import * as S3 from "@aws-cdk/aws-s3";
import * as SSM from "@aws-cdk/aws-ssm";

export class ParameterStack extends CDK.Stack {
  constructor(app: CDK.App, id: string, props?: CDK.StackProps) {
    super(app, id, props);

    const bucket = new S3.Bucket(this, "Bucket", {
      websiteIndexDocument: "index.html",
      publicReadAccess: true,
    });

    new SSM.StringParameter(this, "Parameter", {
      parameterName: "/path/to/parameter",
      description: "Description for your parameter",
      stringValue: bucket.bucketWebsiteDomainName,
    });
  }
}