Skip to content

seanrmurphy/lambda-swagger-test

Repository files navigation

What

A small application to demonstrate the use of go-swagger in an AWS context, linking in the API Gateway and Lambda functions.

Check out this medium post for more information.

Requirements

  • Modern go toolchain - I used go 1.14.6
  • go-swagger - I used v0.25.0
  • AWS SAM application management tool
  • Basic utilities: zip for function upload to AWS, curl and jq for testing

Install

Install this repo using go get

go get github.com/seanrmurphy/lambda-swagger-test

Note that as it makes reference to code which will be generated using swagger tools, go get will generate errors but the content will be there. (It is of course possible to install this using git clone in the appropriate place).

Build, deploy, test, clean up

  • Generate the Swagger server-side stub code
swagger generate server -f swagger.yaml

This will generate models and restapi directories in the main directory. Note that there is another swagger defintion, swagger-req-validation.yaml - this contains some extra content which instructs the AWS API Gateway to perform request validation; it generates exactly the same autogenerated code for the REST API.

  • Build the application
cd deploy
./build.sh

This builds the application in the top level directory of the repo; it copies the resulting executable into the deploy directory.

  • Deploy the application

There are two modes for deploying the application - with and without API Gateway validation - indeed, this sample application highlights the validation performed by the API Gateway.

./deploy-without-gw-validation.sh

This zips the executable and uploads it to AWS using the sam tool and associated configuration file (sam-deploy.toml). On successful completion, it prints the identifier for the Lambda function and the endpoint of the REST API.

  • Run the tests
cd ../tests
export RESTAPI=<ENDPOINT OUTPUT FROM DEPLOYMENT PROCESS>
./tests.sh

The tests demonstrate both successful and unsuccessful calling of all of the endpoints defined in the API.

  • Removing the API

The easiest way to remove the application is via the AWS CloudFormations dashboard.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published