• Stars
    star
    110
  • Rank 315,798 (Top 7 %)
  • Language
    Go
  • License
    MIT License
  • Created over 6 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An example API and Worker written in Golang using the Amazon Serverless Application Model (AWS SAM)

AWS SAM Golang Example

Build Status Go Report Card

An example API and Worker written in Golang using the Amazon Serverless Application Model (AWS SAM).

Overview

Go is arguably one of the easiest languages in which to write a RESTful API. With the addition of Go support for AWS Lambda coupled with the maturity of tooling around the AWS Serverless Application Model, deploying Golang-based APIs to serverless infrastructure is becoming much more straightforward, too. Thanks to the APEX Gateway, you can even write APIs in a familiar manner without changing how the code is structured.

The purpose of this project is to give a slightly more complicated example than the "hello world" ones provided by Amazon with a toolchain that supports both local development and deployment to AWS as well as design patterns that facilitate unit testing.

Prerequisites

Installation

With a correctly configured Go toolchain:

go get github.com/cpliakas/aws-sam-golang-example/...
cd $GOPATH/src/github.com/cpliakas/aws-sam-golang-example

Usage

Run the API Locally

⚠️ Make sure to install all the Prerequisites. On Mac OSX and Windows, ensure that the Docker VM is running.

GOARCH=amd64 GOOS=linux go build -o api ./service/api
sam local start-api

or ...

make run

You can now consume the API using your tool of choice. HTTPie is pretty awesome.

http localhost:3000/
HTTP/1.1 200 OK
Content-Length: 28
Content-Type: application/json; charset=utf8
Date: Sat, 03 Feb 2018 20:12:07 GMT

{
    "message": "Hello, world!"
}

Run the Worker Locally

TODO

Deploy to AWS

First, set the following environment variables replacing <MY-BUCKET-NAME> and <MY-STACK-NAME> as appropriate:

export S3_BUCKET="<MY-BUCKET-NAME>"
export STACK_NAME="<MY-STACK-NAME>"

Now build, package, and deploy the application:

GOOS=linux GOARCH=amd64 go build -o api ./service/api
GOOS=linux GOARCH=amd64 go build -o error ./service/error
GOOS=linux GOARCH=amd64 go build -o worker ./service/worker

sam package --template-file template.yaml --s3-bucket $S3_BUCKET --output-template-file packaged.yaml
sam deploy --stack-name $STACK_NAME --template-file packaged.yaml --capabilities CAPABILITY_IAM

or ...

make deploy

Consume the Endpoint

The API endpoint is captured in the CloudFormation stack's Endpoint output key. Either view the output value via the AWS Management Console, or run the following command assuming the jq tool is installed:

aws cloudformation describe-stacks --stack-name $STACK_NAME | jq -r '.Stacks[0].Outputs[0].OutputValue'

Again, HTTPie is a pretty awesome tool.

View AWS Logs

Run the following command to get the CloudWatch logs for the API.

sam logs -n Api --stack-name $STACK_NAME

Replace Api with Worker or Error to get logs for the Lambda functions in those resources as well.

⚠️ The sam tool will throw a nasty stack trace if you try to view the logs before the Lambda function has been invoked. Only run this command after you have made requests to the corresponding handlers.

More Repositories

1

git-wrapper

A PHP wrapper around the Git command line utility.
PHP
507
star
2

php-project-starter

A command line tool that allows developers to quickly create PHP applications that use common conventions and best-in-breed development tools.
PHP
75
star
3

jira-client

A PHP client for integrating with the JIRA issue & bug tracker software.
PHP
71
star
4

magento-client-php

A PHP client library that consumes Magento's REST and XMLRPC APIs
PHP
55
star
5

psolr

A simple PHP client for Apache Solr that is built on top of Guzzle and inspired by RSolr.
PHP
16
star
6

manifest-publisher

A command line tool that builds and publishes a herrera-io/php-phar-update manifest.json file
PHP
15
star
7

search-framework

A search framework that facilitates reusable code and concepts across search backend libraries.
PHP
13
star
8

dynamo-db-odm

A lightweight ODM for DynamoDB
PHP
10
star
9

drupal-distro

A command line tool that creates and manages Drupal distributions.
PHP
9
star
10

quickbase-sentiment-analysis

A sentiment analysis service for Quickbase
JavaScript
6
star
11

elasticsearch-engine

Provides an Elasticsearch engine to the Search Framework library by leveraging the Elastica project.
PHP
5
star
12

composer-manager-docs

Documentation for Drupal's Composer Manager module https://drupal.org/project/composer_manager
5
star
13

cliutil

Helper functions that simplify writing CLI tools with Cobra and Viper.
Go
4
star
14

simplesamlphp-composer

A Composer-compatible packages.json file for SimpleSAMLphp along with a stupid simple PHP script that generates the file.
PHP
4
star
15

doctrine-password

Adds a password type to Doctrine that hashes and compares passwords using the phpass library.
PHP
4
star
16

git-sync

Synchronizes Git repositories.
PHP
3
star
17

cgo-example

A simple CGO application for example purposes.
Go
3
star
18

silex-drupal-integration

Adds a Drupal authentication provider for Silex and a client library that communicates with Drupal via the Services module.
PHP
3
star
19

fastwalk

A copy of the fastwalk code inside of Go Tools with exported functions for use as a standalone library.
Go
2
star
20

feed-collection

Provides an RSS / Atom feed collection to the search framework library.
PHP
2
star
21

bigoven-php

A PHP client library for the BigOven API
PHP
2
star
22

solr-search-engine

Provides a Solr search server to the Search Framework library by leveraging the Solarium project.
PHP
2
star
23

scanner

A Go package that provides a recursive file scanner that is useful for efficiently processing large and relatively static datasets.
Go
2
star
24

finance

A Golang library and command line tool that executes finance calculations and operations.
Go
2
star
25

fileinfo

A go package that extracts and stores basic metadata about a file.
Go
1
star
26

quickbase-pipelines-auth

1
star
27

solarium-statsjsp

A stats.jsp request handler for Solarium.
PHP
1
star
28

quickbase-action-test

1
star
29

wh-test

Github Webhooks testing.
Go
1
star
30

Acquia-Cloud-Utilities

Deprecated: See https://github.com/acquia/acquia-sdk-php
PHP
1
star
31

goreleaser-test

Test of goreleaser that serves as a working example.
Makefile
1
star
32

quickbase-deploy-action

Shell
1
star
33

nagiostatus

PHP parser library for the Nagios status.dat file.
PHP
1
star
34

solarium-system

An admin/system request handler for Solarium.
PHP
1
star
35

quickbase-test-action

Shell
1
star
36

quickbase-textmate

A command line tool that automates creation to TextMate grammar for use with VS Code
Go
1
star
37

git-collection

Provides collection of Git logs and diffs to the search framework library.
PHP
1
star
38

quickbase-do-query

A command line tool that gets records from a Quick Base table.
Go
1
star