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

@matthewbonig/cdk-logical-id-mapper

v0.0.2

Published

Have you ever used the CDK's [.overrideLogicalId](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.CfnResource.html#overridewbrlogicalwbridnewlogicalid) method? Chances are you were using it wrong. This is bad:

Downloads

890

Readme

A CDK Logical ID Mapper

Have you ever used the CDK's .overrideLogicalId method? Chances are you were using it wrong. This is bad:

const topic = new Topic(stack, 'SomeTopic');
(topic.node.defaultChild as CfnResource).overrideLogicalId('MyTopic')

You shouldn't do this because the LogicalId is an aspect of the stack instance, and here you're making it an aspect of the stack definition. So if you create this stack multiple times, you override the logicalId in all of the stack instances.

Chances are you need to override the logicalId of a record because you just refactored a bunch of your code, either changing Ids or nesting constructs in other constructs. Both things change your logicalIds. If you've deployed your stack before to an environment then changing logicalIds will cause a recreation of the resources and that might cause some serious issues as stateful resources get deleted, or you run into naming conflicts (if you're naming your resources explicitly), or worse, you introduce an outage or lose data.

This library has one class in it, LogicalIdMapper that implements the IAspect interface, so you use it as an aspect to a specific scope. Like all aspects, it is given every resource in your scope and if it's found in the given map, it will override the logicalId.

This has two primary advantages:

  1. You don't pollute your stack code with logicalId overrides which makes things hard to read and hard to maintain.
  2. You allow overrides to happen at a per-stack level instead of across all your stacks.

Usage


const app = new App();
const stack = new Stack(app, 'TestStack');

new Topic(stack, 'SomeTopic');

Aspects.of(stack).add(new LogicalIdMapper({
  map: {
    SomeTopicDB89918F: 'MyTopic', // rename the SomeTopicDB89918F logical ID to MyTopic
  }
}));

For cdk-pipeline stages:


const stage = new Stage(this, 'MyPipelineStage');

Aspects.of(stage).add(new LogicalIdMapper({
  map: {
    SomeTopicDB89918F: 'MyTopic', // rename the SomeTopicDB89918F logical ID to MyTopic
  }
}));

pipeline.addStage(stage);

Contributions.

If you have Issues, yo, I'll solve it.