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

cdk-pipelines

v1.11.0

Published

Codepipelines for s3 and lambda

Downloads

23

Readme

Codepipeline Construct Library

To use first create a cdk project like this:

mkdir foo
cd foo

Next create folders for the lambda, tests and the cdk project for example:

mkdir resources
mkdir src
mkdir tests

Then generate the actual cdk project by (this will generate a default ResourceStack):

cd resources
cdk init app --language typescript

Develop the lambda code and tests, when done commit the project to codecommit for example (foo-lambda-repo)

Next create a stack for the lambda (foo-lambda-stack.ts) inside the lib folder of the cdk project /resources/lib like so:

...
import * as lambda from '@aws-cdk/aws-lambda'

export class FooLambdaStack extends cdk.Stack {

    public readonly lambdaCode: lambda.CfnParametersCode;

    constructor(scope: cdk.Construct, id: string, props?:cdk.StackProps) {
        super(scope, id, props)

        this.lambdaCode = lambda.Code.fromCfnParameters();

        const func = new lambda.Function(this, 'FooLambda', {
            code: this.lambdaCode,
            handler: 'foo.handler',
            runtime: lambda.Runtime.PYTHON_3_8,
            description: `Generated on: ${new Date().toISOString()}`,
        });        
    }
}

Next using the project generated Stack in this case ResourcesStack You can generate a lambda codepipeline like this:

...
import { LambdaPipeline } from 'cdk-pipelines'

export interface ResourcesStackProps extends cdk.StackProps {
	  readonly lambdaCode: lambda.CfnParametersCode;
}

export class ResourcesStack extends cdk.Stack {
  constructor(scope: cdk.Construct, id: string, props: CdkTestStackProps) {
    super(scope, id, props);

    new LambdaPipeline(this, "FooLambdaPipelineStack", {
      codeRepositoryName:'foo-lambda-repo',
      cdkFolderName: 'foo',
      lambdaCodeFolderName: 'src',
      lambdaCode: props.lambdaCode,
      installCommands: [
          'pip install -r requirements.txt'
      ],
      buildCommands: [
          'python -m pytest -v -s tests --disable-pytest-warnings'
      ],
      artifactBaseDir:'src',
      artifactFiles: [
          '**/*'
      ],
      runtime: {python : 3.8}
    })
  }
}

Next update the resources.ts file in the bin directory to use the two stacks lambda, pipeline like so:

...
import { FooLambdaStack } from '../lib/foo-lambda-stack';
import { ResourcesStack } from '../lib/resources-stack';

const app = new cdk.App();
const lambdaStack = new FooLambdaStack(app, 'FooLambdaStack');
new ResourcesStack(app, 'ResourcesStack', {
    lambdaCode: lambdaStack.lambdaCode 
});

Finally update your test under resources/test/resources.test.ts

The directory structure should look this this:

.
├── requirements.txt
├── resources
│   ├── README.md
│   ├── bin
│   │   └── resources.ts
│   ├── cdk.json
│   ├── jest.config.js
│   ├── lib
│   │   ├── foo-lambda-stack.ts
│   │   └── resources-stack.ts
│   ├── package-lock.json
│   ├── package.json
│   ├── test
│   │   └── resources.test.ts
│   └── tsconfig.json
├── src
│   └── lambda.py
└── tests
    └── test_lambda.py

Before you deploy make sure this code is also commited to codecommit.

To deploy the codepipeline do this:

npm run build
cdk deploy ResourcesStack

This will build the codepipeline which will now pull the source code from the codecommit repo (foo-lambda-repo), and build the lambda stack from there.