All Projects → Giftbit → sam-scaffold

Giftbit / sam-scaffold

Licence: Apache-2.0 license
A template for an AWS SAM project with continuous integration.

Programming Languages

javascript
184084 projects - #8 most used programming language
shell
77523 projects
typescript
32286 projects
go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to sam-scaffold

Hands-On-Serverless-Applications-with-Go
Hands-On Serverless Applications with Go, published by Packt.
Stars: ✭ 92 (+15%)
Mutual labels:  cloudformation, sam
Aws Cognito Apigw Angular Auth
A simple/sample AngularV4-based web app that demonstrates different API authentication options using Amazon Cognito and API Gateway with an AWS Lambda and Amazon DynamoDB backend that stores user details in a complete end to end Serverless fashion.
Stars: ✭ 278 (+247.5%)
Mutual labels:  cloudformation, sam
Gofaas
A boilerplate Go and AWS Lambda app. Demonstrates an expert configuration of 10+ AWS services to support running Go functions-as-a-service (FaaS).
Stars: ✭ 731 (+813.75%)
Mutual labels:  cloudformation, sam
Aws Sso Util
Smooth out the rough edges of AWS SSO (temporarily, until AWS makes it better).
Stars: ✭ 208 (+160%)
Mutual labels:  cloudformation
Aws Toolkit Eclipse
AWS Toolkit for Eclipse – an open-source plugin for developing, deploying, and managing AWS applications.
Stars: ✭ 252 (+215%)
Mutual labels:  cloudformation
matlab-production-server-on-aws
Stand up a MATLAB Production Server using CloudFormation
Stars: ✭ 21 (-73.75%)
Mutual labels:  cloudformation
aws-batch-example
Example use of AWS batch
Stars: ✭ 96 (+20%)
Mutual labels:  cloudformation
Checkov
Prevent cloud misconfigurations during build-time for Terraform, Cloudformation, Kubernetes, Serverless framework and other infrastructure-as-code-languages with Checkov by Bridgecrew.
Stars: ✭ 3,572 (+4365%)
Mutual labels:  cloudformation
serverless-discord-bot
A serverless Discord Bot template built for AWS Lambda based on Discord's slash commands and the slash-create library.
Stars: ✭ 37 (-53.75%)
Mutual labels:  cloudformation
cloudformation-resource-schema
The CloudFormation Resource Schema defines the shape and semantic for resources provisioned by CloudFormation. It is used by provider developers using the CloudFormation RPDK.
Stars: ✭ 77 (-3.75%)
Mutual labels:  cloudformation
Nietzsche
Scrap quotes from Goodreads and schedule random tweets.
Stars: ✭ 44 (-45%)
Mutual labels:  cloudformation
cljam
A DNA Sequence Alignment/Map (SAM) library for Clojure
Stars: ✭ 85 (+6.25%)
Mutual labels:  sam
cloudwatch-dashboards-cloudformation-sample
A sample project to demonstrate using Cloudformation, how to create and configure CloudWatch metric filters, alarms and a dashboard to monitor an AWS Lambda function.
Stars: ✭ 61 (-23.75%)
Mutual labels:  cloudformation
Docs
Rapid CloudFormation: Modular, production ready, open source.
Stars: ✭ 209 (+161.25%)
Mutual labels:  cloudformation
cfn-include
Preprocessor for CloudFormation templates with support for loops and flexible include statements
Stars: ✭ 83 (+3.75%)
Mutual labels:  cloudformation
Cluster Lifecycle Manager
Cluster Lifecycle Manager (CLM) to provision and update multiple Kubernetes clusters
Stars: ✭ 200 (+150%)
Mutual labels:  cloudformation
aws-customer-churn-pipeline
An End to End Customer Churn Prediction solution using AWS services.
Stars: ✭ 30 (-62.5%)
Mutual labels:  cloudformation
aws-pdf-textract-pipeline
🔍 Data pipeline for crawling PDFs from the Web and transforming their contents into structured data using AWS textract. Built with AWS CDK + TypeScript
Stars: ✭ 141 (+76.25%)
Mutual labels:  cloudformation
bioSyntax-archive
Syntax highlighting for computational biology
Stars: ✭ 16 (-80%)
Mutual labels:  sam
paco
Paco: Prescribed automation for cloud orchestration
Stars: ✭ 32 (-60%)
Mutual labels:  cloudformation

sam-scaffold

A template for an AWS SAM project with continuous integration.

SAM is an extension of AWS's CloudFormation that makes it easier to define serverless applications. It is unopinionated on language choice, build tools, or project layout. This example project provides a set of opinions on those choices. It can be cloned and used as is to get a serverless project up and running quickly, or it can be used as a guideline for your own project.

This project features templates for Go, JavaScript ES2015 and TypeScript. READMEs in each project directory provide language-specific information.

Project Structure

.
├── dev.sh
├── infrastructure
│   └── sam.yaml
└── src
    └── lambdas
        └── ...

The behaviour of a lambda function is determined by its source code (inside a subdirectory of src/lambdas) and the other serverless resources it has access to (inside the CloudFormation template infrastructure/sam.yaml).

dev.sh

Building the project and managing the development account is easily done with the included script dev.sh. The script requires the aws cli installed and configured for a development account. For security reasons this should not be your production account. It also requires bash, which is a useful tool even on Windows.

Edit the top of dev.sh and replace STACK_NAME with a name that describes the project and replace BUILD_ARTIFACT_BUCKET with the name of an S3 bucket you have access to for build artifact storage.

These are the commands you can use...

  • ./dev.sh build foo -- compile only the lambda function foo
  • ./dev.sh deploy -- deploy the entire CloudFormation stack including all source code to the currently configured aws cli account.
  • ./dev.sh upload foo -- only replace the the code for the lambda function foo.
  • ./dev.sh invoke foo bar.json -- invoke and test the already deployed function foo with the input file bar.json.
  • ./dev.sh delete -- delete the entire CloudFormation stack and all resources.

Adding a new lambda function

Add a new directory inside src/lambdas named after your function. Inside there add a file index.ts if you're working in TypeScript or index.js if you're working in JavaScript. The file must have an export function handler that will be called by AWS.

Add a new AWS::Serverless::Function resource inside infrastructure/sam.yaml. Name it after your function with the first letter capitalized. Set the CodeUri to be the dist zip file that will be generated. eg: if your folder is src/lambdas/fooBar name your resource FooBarFunction with CodeUri: ../dist/fooBar/fooBar.zip.

Continuous Integration

.
├── buildspec.yml
└── infrastructure
    ├── ci.yaml
    └── sam.yaml

Continuous integration is set up through another CloudFormation stack infrastructure/ci.yaml. This stack defines a CodePipeline that builds the project with CodeBuild, which runs the commands in buildspec.yml, and one of those commands deploys the SAM stack with CloudFormation. It's a CloudFormation stack that deploys another CloudFormation stack!

Again, for clarity: sam.yaml defines the SAM stack that is the definition of all your lambda functions and their resources; buildspec.yml defines your compile and deploy commands; ci.yaml defines the CI stack that watches for git repo changes and redeploys the SAM stack automatically.

The CI stack itself is not deployed automatically on changes. It must be deployed manually. This was chosen to increase the effort necessary to attack the account. The CI stack should rarely need to change. For help manually deploying a CloudFormation stack see the relevant AWS documentation.

Build secrets

You may run into a scenario where you need access to secrets during the build process. For example you have a private repository of packages and need an SSH key to access them.

The best way to handle these secrets is store them in an S3 bucket, give the CodeBuildServicePolicy permission to read that bucket, and then use aws cli commands to retrieve the secrets.

For example add this to ci.yaml:

# under CodeBuildServicePolicy.Properties.PolicyDocument.Statement
- Effect: Allow
  Action:
    - s3:GetObject
    - s3:ListBucket
  Resource:
    - !Sub "arn:aws:s3:::${MyBucketOfSecrets}"
    - !Sub "arn:aws:s3:::${MyBucketOfSecrets}/*"
  Principal:
    AWS: !GetAtt CiKeysAccessRole.Arn

# under CodeBuildProject.Properties.Environment.EnvironmentVariables
- Name: BUCKET_OF_SECRETS
  Value: !Ref MyBucketOfSecrets

and add this to buildspec.yml:

# under phases.install.commands
- aws s3 sync s3://BUCKET_OF_SECRETS/ ~/secrets

Setting up single stage CI

Single stage CI consists of only one CodePipeline. A single branch is watched for changes. When deploying for a single stage leave the GitHubBranchDest field empty.

The sequence of events goes like this:

  • a pull request is merged into the master branch
  • a git trigger causes CodePipeline to begin a release
  • CodeBuild fetches the release from GitHub
  • CodeBuild launches the build Docker image and runs the commands specified in buildspec.yml
  • the output artifacts are stored in S3
  • CloudFormation creates a change set for the SAM stack
  • a developer approves the changeset
  • CloudFormation executes the change set for the SAM stack

Setting up two stage CI

Two stage CI consists of two CodePipelines. The first CodePipeline watches a staging branch and deploys to a staging account. After successfully deploying and testing in staging the code is merged into a prod branch where the process repeats in production.

The sequence of events goes like this:

  • a pull request is merged into the staging branch
  • a git trigger causes the staging CodePipeline to begin a release
  • CodeBuild fetches the release from GitHub
  • CodeBuild launches the build Docker image and runs the commands specified in buildspec.yml
  • the output artifacts are stored in S3
  • CloudFormation creates a change set for the SAM stack
  • a developer approves the changeset
  • CloudFormation executes the change set for the SAM stack on staging
  • a lambda function creates and merges a pull request from the staging branch to the master branch
  • a git trigger causes the prod CodePipeline to begin a release
  • CodeBuild fetches the release from GitHub
  • CodeBuild launches the build Docker image and runs the commands specified in buildspec.yml
  • the output artifacts are stored in S3
  • CloudFormation creates a change set for the SAM stack
  • a developer approves the changeset
  • CloudFormation executes the change set for the SAM stack on prod

Contributors

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].