go-hello-world-lambda-gateway-cognito

command module
v0.0.0-...-dbe45ff Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 28, 2024 License: MIT Imports: 8 Imported by: 0

README

go-hello-world-lambda-gateway-cognito

Simple Go Lambda API Gateway with Cognito Authorization SAM Template Example

Requirements

Local development

  1. Build the go executable for the lambda linux environment

    GOARCH=arm64 GOOS=linux go build -o bootstrap main.go
    
  2. Zip project (Windows)

    C:\Users\owner\go\bin\build-lambda-zip.exe -o lambda-handler.zip bootstrap using the provided build-lambda-zip package. If needed, you can install with go install github.com/aws/aws-lambda-go/cmd/build-lambda-zip@latest. See To create a .zip deployment package (Windows)

  3. Invoke function locally through local API Gateway

    sam.cmd local start-api --template-file=template.yaml
    

    Note: Use sam.cmd when running AWS SAM on windows

    To rebuild and apply local changes, use sam.cmd build --use-container

  4. (Optional) Run CRUD Requests Individually

    Can also run CRUD API requests by importing the /bruno collection

Deployment

Ensure you follow the same steps you did to build the executable and zipping the project

  1. Build the go executable for the lambda linux environment

    GOARCH=arm64 GOOS=linux go build -o bootstrap main.go
    
  2. Zip project (Windows)

    C:\Users\owner\go\bin\build-lambda-zip.exe -o lambda-handler.zip bootstrap using the provided build-lambda-zip package. If needed, you can install with go install github.com/aws/aws-lambda-go/cmd/build-lambda-zip@latest. See To create a .zip deployment package (Windows)

  3. Deploy CloudFormation stack template

    sam.cmd deploy --guided --template-file=template.yaml
    

Login

The provided SAM template does not allow any user to sign up. Only designated users in the AWS Cognito Pool can login.

Create Cognito User
  1. Login to AWS Console

  2. Navigate to CloudFormation

  3. Click on this CloudFormation Stack

  4. Navigate to Resources

  5. Click on UserPool Physical ID Link

  6. Click Create User

  7. Add User Details and Create User

Login to AWS Cognito
  1. Navigate to CloudFormation Stack

  2. Navigate to Outputs

  3. Click on LoginURL Value

  4. Login with Created User Credentials

  5. Obtain Access Token

Perform Authorized Request
  1. Navigate to CloudFormation Outputs

  2. Obtain GatewayAPIEndpoint Value

  3. Perform POST Request with Endpoint Value on /Dev/api/any Route with Bearer Token in Authorization Header

  4. Verify username and email Values are Present in Response

  5. (Optional) Check CloudWatch Logs

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL