GithubHelp home page GithubHelp logo

versent / golang-lambda-pipeline Goto Github PK

View Code? Open in Web Editor NEW
13.0 6.0 2.0 359 KB

A sample golang serverless application, with multi-account CI/CD via CodePipeline

License: MIT License

Go 51.36% Makefile 48.64%
aws lambda codepipeline codebuild golang cloudformation

golang-lambda-pipeline's Introduction

Golang Lambda Pipeline

This repository contains a serverless application, and multi-stage pipeline to perform CI/CD on it.

Setup

  1. Launch the deploy role template to the deploy accounts, passing the build account's id.
  2. Gather the cross-account role ARNs from the stacks' outputs.
  3. Deploy the pipeline and its dependencies template to the build account, passing the deploy role ARNs and other parameters.
  4. Get the repository URL from the pipeline's stack outputs.
  5. Push this repository's code to the repository to trigger a build and deployment to the staging account.
  6. Manually approve the deployment in to the production account.
  7. Profit!

Accounts

Multiple accounts are used so that:

  • Blast radius is limited. Issues in the deploy accounts cannot impact other deploy accounts.
  • No runtime dependencies on the pipeline. The pipeline resources (and the associated resources) can be removed without impacting the running application.

While multiple accounts are part of the architecture, nothing is stopping you from using less accounts - just supply the same Account Id in multiple locations (e.g. when the pipeline and repo are in the production account). The same deployment role can be used for both the staging and production stages, and they can all be in the same account.

Recommended

The recommend deployment pattern is a "pipline in production" approach This is based on the reasoning that anything that can modify production, is production:

Alternative

Some setups involve the idea of a "build" environment, which is a production-like environment that is separate from the application's production environment (usually for administrative reasons).

This approach can also work, as long as appropriate controls are in place on the build environment:

Application

SAM Template

A serverless application (using AWS SAM) template is included to simulate a real-world application. The application consists of a golang Lambda function (with tests), and API Gateway endpoint.

The application's build is managed via a CodeBuild buildspec.yaml file. All of the tasks are managed via make.

Deploy Accounts

The accounts where the application will be deployed (e.g. staging and production). These accounts must have some resources deployed in them to facilitate the pipeline's access to deploy (e.g. cross-account role, etc).

  • Changes are deploy to the same named stacks e.g. ApplicationName-staging.
  • Changes are automatically applied to the staging stack.
  • Manual approval is required before a change set is created in production, and before the change set is applied (i.e. there are two approvals required).

Design

Pipeline Stages

Pipeline Stages

Build Pipeline

This high-level diagram represents the resources that are created by the dependencies-tempalate.yaml.

Build Resources

  1. Developers push code.
  2. Pipeline is triggered by commits to master.
  3. A build container builds the source using make commands (defined in buildspec.yaml).
  4. Build artefacts are packaged and stored for deployment in S3 using aws cloudformation package.
  5. The change set is automatically deployed to the staging environment stack.
  6. The change must be manually approved before anything is deployed to production.
  7. The change set is applied to the production stack, and must then be approved again before it is deployed.

Deploy Account

The following resources are created and referenced in the deploy accounts:

Deploy Account

Links

golang-lambda-pipeline's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

gezza-b euphio

golang-lambda-pipeline's Issues

Split dependencies template in to layers?

Would this be too complicated as a starting point/demo application + pipeline? It would add extra deployment steps.

Specifically: splitting out the buckets would enable the cross-account roles to specifically mention them, further limiting the access they require.

Run CodeBuild container locally

Is this worth the effort? If the build process leverages too many (any?) remote services, this might not be practical/valuable...

Add recipes to makefile so that buildspec.yaml can be run locally in a simulate CodeBuild environment.

Use the official CodeBuild images.

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.