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

vpc-export-import

v0.0.8

Published

Unlike AWS CDK Constructs like DynamoDB, AWS did not provide the ability to easily export a VPC from one stack and import it in another. You can do it, but it's complicated, not documented anywhere, and makes your code messy. This Construct was designe

Downloads

6

Readme

AWS CDK Construct - export VPC from one stack, import to another

Unlike AWS CDK Constructs like DynamoDB, AWS did not provide the ability to easily export a VPC from one stack and import it in another. You can do it, but it's complicated, not documented anywhere, and makes your code messy. This Construct was designed to solve that problem.

Why would one want to export and import a VPC? Best practices. If for some reason you have to destory part of your application to redeploy it, you shouldn't destroy your VPCs (or your databases, or...). In other words stacks instances should be small and modular. Just like any good code or deployment.

Sure, you could manually create your VPCs and hard-code references to them, but this makes automatic creation of sandboxes very difficult or impossible, and isn't a very good practice in general.

Object Structure of a VPC

per the CDK object model, which mirrors that of the CFT and thus the underlying objects in AWS.

    VPC --- AvailabilityZones []
        --- Subnets (3 types) []
            --- RouteTables []
        --- vpnGatewayId
        --- vcpCidrBlock 
        --- ...

If you don't export the IDs of every one of these items and import them, you canmot recreate the VPC without warnings, subtle failures in other entities such as EFS and Lambda, or outright failures. There are no working examples, AFAICT, of doing so. Now, there is.

Usage

Anywhere you want to export a VPC from its and all its associated components from its creation Stack and import the VPC and its associated components into another Stack.

Module Usage

  1. Add Module:

     npm install --save cdk-vpc-export-import
  2. Import Statement:

     import VpcPortable from 'cdk-vpc-export-import';
  3. General usage:

Use like any Ec2.Vpc. Call the function exportToStackOutput() to export from the stack, and in the stack that needs to use the vpc instance, call the static function importFromStackOutput(), which follows the similar pattern to other fromXXX() in the CDK. The object returned is a Ec2.Vpc that can be assigned as the network for a Lambda function, the network for an EFS file system, etc.

  1. Use of global exports namespace on AWS

The stack exports functionality of CFT/CDK is used, which is a global namespace. The name is mangled with the stack name, the node.id of your VPC instance, and the names of the fields. If for some unlikely reason you get a collision or see problem please file an issue. It would be easy to implement options for alternative naming algorithms.

Testing And Development

See the corresponding repo for integration test, which is the only real way to test a VPC construct especially one that crosses stacks.