Giter Site home page Giter Site logo

golanglambda's Introduction

GolangLambda

GolangLambda is a npm package for AWS CDK that makes creating Lambdas with Golang extremely simple. No need to figure out how/when to build your code because GolangLambda will build it for you within a Docker container. The best part is that this means your code builds anywhere that has docker installed, including within a CDK Pipeline. ๐Ÿ˜Ž

Requirements

  • Docker
  • NPM
  • Experience writing if err != nil ...

Installation

npm install golanglambda

How to Use

import { GolangLambda } from "golanglambda";

const myLambda = new GolangLambda(this, 'my-lambda');

Note the id given to the GolangLambda constructor. This is used for a few things other than the id of the CDK resource itself. It is used as the lambda.handler and executable name as well as the directory that contains the main.go. GolangLambda assumes that your Go source code will be located in a "cmd" directory at the root of the project. This gives you a nice place to keep all of your Go code but don't worry if you want to change this you can, see below.

Testing (go test)

Testing your Go code happens by default automatically when running cdk synth or cdk deploy. You can disable this step by setting testingEnabled: false.

Building (go build)

Building your Go code happens automatically when running cdk synth or cdk deploy. However, there are a few things to note about the build process.

  1. The entire sourcePath directory is copied into the build container. This is true whether you set sourcePath or not. The intention here is to allow code sharing between multiple lambdas in the project.
  2. sourcePath is determined relative to project_root/node_modules/golanglambda/lib so if for some reason your node_modules is located elsewhere you will probably need to set sourcePath explicitly.
  3. When using CDK Pipelines you must set privileged: true in order for the build stage to have access to Docker.

Configuration

In typical CDK fashion, GolangLambda exposes configuration via the GolangLambdaProps interface. This interface extends CDK's FunctionOptions which means you have access to all the underlying lambda's props as well.

Lambda Timeout & Memory
import { GolangLambda } from "golanglambda";

const myLambda = new GolangLambda(this, 'my-lambda', {
    timeout: Duration.seconds(30),
    memorySize: 128
});
Lambda Environment Variables
import { GolangLambda } from "golanglambda";

const myLambda = new GolangLambda(this, 'my-lambda', {
    environment : {
        "DYNAMODB_TABLE_NAME" : "my-table"
    }
});
Lambda VPC Access
import { GolangLambda } from "golanglambda";

const vpc = ...
const securityGroup = ...

const myLambda = new GolangLambda(this, 'my-lambda', {
    vpc: vpc,
    vpcSubnets: {
        subnetType: SubnetType.PRIVATE,
    },
    securityGroups: [
        securityGroup
    ]
});
Build Time Access to private Repo
import { GolangLambda } from "golanglambda";

const myLambda = new GolangLambda(this, 'my-lambda', {
    bundlingCommands: [
        'git config --global url."https://oauth2:[email protected]".insteadOf  "https://gitlab.com"'
    ],
});

Issues

Submit an issue. PRs welcome.

License

MIT

golanglambda's People

Contributors

kyleishie avatar

Watchers

James Childs avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.