npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cdk8s-aws-lookups

v0.0.7

Published

A cdk8s lookup class that allows you to lookup AWS CloudFormation outputs and AWS SSM parameter values during synth time from CloudFormation stacks.

Downloads

146

Readme

AWS Lookups for cdk8s

This library provides a simple way to lookup AWS resources from your cdk8s project during synthesis time. Lookups are being cached in the cdk8s.context.json file in the root of your project. Values are looked up using the AWS SDK if they are not in the cache, and then if found, stored in the cache. Subsequent synth runs will then use the cached values. If you want to refresh the lookup, you will have to evict the value from the cache. You can do that by deleting the value from the cdk8s.context.json file, or to delete the whole file.

In order to perform the lookup using the AWS SDK, you will need to have the AWS credentials set up on your machine. By default, the library will try to use the aws-cdk lookup pattern, which tries to sts assume the role pattern arn:aws:iam::accountid:role/cdk-hnb659fds-lookup-role-accountid-region-id, but if it fails to do so because this was not set up, it will use the standard AWS Credential flow for the lookup. If you are unfamiliar on how to configure credentials for AWS, please refer to the AWS SDK documentation or the AWS CDK documentation.

Cloudformation Outputs Lookup

The AwsCloudformationOutputs is able to lookup any StackOutput defined by your deployed AWS CDK application. It does that by implementing the lookup Pattern of aws-cdk in cdk8s, using the lookupOutput() method.

Usage:

You can simply use the AwsCloudformationOutputs class in your cdk8s project. The lookupOutput method will return the value of the output you are looking for at synthesis time.

import { Chart } from "cdk8s";
import * as kplus from "cdk8s-plus";
import { AwsCloudformationOutputs } from "cdk8s-aws-lookups";

class MyChart extends Chart {
  constructor(scope: Construct, id: string, stackName: string) {
    super(scope, id);

    const cfOutputs = new AwsCloudformationOutputs(stackName, {
      account: awsAccID,
      region: awsRegion,
    });
    const databaseConnectionString = cfOutputs.lookupOutput(
      "DatabaseConnectionString"
    );

    const deployment = new kplus.Deployment(this, "MyDeployment");
    const container = deployment.addContainer({
      image: "my-app-image",
      env: {
        DATABASE_CONNECTION_STRING: databaseConnectionString,
      },
    });
  }
}
import { ApiObject, App, Chart, Testing } from "cdk8s";
import { Construct } from "constructs";
import { AwsCloudformationOutputs } from "cdk8s-aws-lookups";

class MyExampleChart extends Chart {
  constructor(scope: Construct, id: string) {
    super(scope, id);

    const awsAccID = process.env.AWS_ACC_ID || "111111111111";
    const stackName = process.env.STACK_NAME || "my-stack";
    const awsRegion = process.env.AWS_REGION || "eu-west-1";

    if (!awsAccID || !stackName) {
      throw new Error(
        "AWS_ACC_ID and STACK_NAME environment variables must be exported for the synth to to run."
      );
    }

    const cfOutputs = new AwsCloudformationOutputs(stackName, {
      account: awsAccID,
      region: awsRegion,
    });
    const databaseConnectionString = cfOutputs.lookupOutput("your-output-name");

    new ApiObject(this, "ConfigMap", {
      apiVersion: "v1",
      kind: "ConfigMap",
      data: {
        Outputs: {
          DATABASE_CONNECTION_STRING: databaseConnectionString,
        },
      },
    });
  }
}

AWS SSM Parameters Lookup

The AwsSsmParameters is able to lookup any SSM Parameter defined by your deployed AWS CDK application. It does that by implementing the lookup Pattern of aws-cdk in cdk8s, using the lookupParameter() method.

Usage:

class MyTestChart extends Chart {
  constructor(scope: Construct, id: string) {
    super(scope, id);

    const awsAccID = process.env.AWS_ACC_ID; // or pass in via constructor
    const awsRegion = process.env.AWS_REGION || "eu-west-1";

    const awsSsmParameters = new AwsSsmParameters({
      account: awsAccID,
      region: awsRegion,
    });
    const specificParameterValue = ssmParameters.lookupParameter("/aaa/test");

    new ApiObject(this, "ConfigMap", {
      apiVersion: "v1",
      kind: "ConfigMap",
      data: {
        Outputs: {
          SPECIFIC_PARAMETER_VALUE: specificParameterValue,
        },
      },
    });
  }
}