Skip to content

gwl/aws-lambda-in-go-lang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AWS Lambda in GoLang — The Ultimate Guide

Revised: Monday, December 26, 2022

A tutorial project for AWS Lambda in Golang This tutorial project builds with Go 1.19 on macOS for AWS Lambda/Linux

What is this repository for?

This is a tutorial project which demonstrates the use of the DynamoDB persistent store with AWS Lambda in Go.

How do I get set up? (initial build instructions)

The instructions in the tutorial are pretty good. These two additional bits might help...

  1. Create the folder structure for this project in your ~/go project folder…
  • % cd ~/go
  • % mkdir aws-lambda-in-go-lang
  • % cd aws-lambda-in-go-lang
  • % go mod init aws-lambda-in-go-lang
  • % mkdir build cmd pkg pkg/user pkg/handlers pkg/validators
  • % git init
  1. IMPORTANT BUILD NOTE: The tutorial has the remaining instructions, with one minor error. The author happens to be building on the same architecture as the AWS Lambda host (Linux/amd64). If your build system is somewhere else (say, macOS) you'll need to modify the build instruction, thusly:
  • % GOARCH=amd64 GOOS=linux go build -o build/main cmd/main.go [or, to build and zip it in one step…]
  • % GOARCH=amd64 GOOS=linux go build -o build/main cmd/main.go && zip -jrm build/main.zip build/main

Testing it

You can poke it with a web browser and it will provide the list of entires in the database as JSON.

You'll need to replace the URL with your own.

  1. add a new user…
  • % curl --header "Content-Type: application/json" --request POST --data '{"email": "jonnyquest@example.com", "firstName": "Jonny", "lastName": "Quest"}' https://YOUR-Lambda-URL.execute-api.us-east-1.amazonaws.com/staging

{"email":"jonnyquest@example.com","firstName":"Jonny","lastName":"Quest"}

  1. list all users…
  • % curl -X GET https://YOUR-Lambda-URL.execute-api.us-east-1.amazonaws.com/staging

[{"email":"s.karasiewicz@softkraft.co","firstName":"Sebastian","lastName":"Karasiewicz"},{"email":"jonnyquest@example.com","firstName":"Jonny","lastName":"Quest"},{"email":"mork@example.com","firstName":"Mork","lastName":"FromOrk"}]

  1. fetch the record of a user given email address…
  • % curl -X GET https://YOUR-Lambda-URL.execute-api.us-east-1.amazonaws.com/staging\?email\=jonnyquest@example.com

{"email":"jonnyquest@example.com","firstName":"Jonny","lastName":"Quest"}

  1. update a user record
  • % curl --header "Content-Type: application/json" --request PUT --data '{"email": "s.karasiewicz@softkraft.co", "firstName": "Sebas", "lastName": "Karasiewicz"}' https://YOUR-Lambda-URL.execute-api.us-east-1.amazonaws.com/staging
  1. delete a user…
  • % curl -X DELETE https://YOUR-Lambda-URL.execute-api.us-east-1.amazonaws.com/staging\?email\=s.karasiewicz@softkraft.co

Resources

AWS Toolkit for JetBrains

Contribution guidelines

About

AWS Lambda in Golang tutorial

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages