Code Monkey home page Code Monkey logo

aws-sam-golang-docker's Introduction

aws-sam-golang-docker

Boilerplate/Starter Project for building Serverless Lambda functions with AWS SAM, Golang, Docker.

Features

  • AWS SAM
  • Golang
  • MySQL
  • Docker
  • Automated packaging and deploying with CircleCI
  • Load environment variables from .env files

Pre Requirements

Getting Started

git clone https://github.com/okmttdhr/aws-sam-golang-docker.git
cd aws-sam-golang-docker
cp .env.sample .env
docker-compose build
docker-compose up

サーバーが立ち上がると、イベントに応じてLambda関数が実行される。 トリガーイベントはjsonを使用して発火することができるが、詳細は下記のリンクを参考にすること。

例 (API Gatewayがトリガーの場合)

curlなどでAPIにアクセスする。

curl -H 'Content-Type:application/json' http://localhost:3000 -X POST -d "Paul"

ユニットテスト

# 全テストを実行
docker-compose run go go test

環境変数の追加

.envファイルに環境変数を追加することで、ローカル環境では環境変数が読み込まれる。

ただし、CloudFormationでのデプロイ時に環境変数を読み込むために、template.ymlを以下のように変更する必要がある。

  • Parametersに値を追加
  • Resources >> 該当のLambda関数 >> Environment!Ref 該当の環境変数名を追加

各環境へのビルド、デプロイ

各種ブランチへのプッシュを行うことで、CircleCIにより該当する環境へのビルド/デプロイが実施される。

  • master / ステージング
  • release / 本番

aws-sam-golang-docker's People

Contributors

okmttdhr avatar

Stargazers

 avatar

Watchers

 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.