Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ryichk/go-echo-lambda-function-url-template
Template for publishing Go's Echo Web app with Lambda Function URL using Lambda Web Adapter.
https://github.com/ryichk/go-echo-lambda-function-url-template
Last synced: 29 days ago
JSON representation
Template for publishing Go's Echo Web app with Lambda Function URL using Lambda Web Adapter.
- Host: GitHub
- URL: https://github.com/ryichk/go-echo-lambda-function-url-template
- Owner: ryichk
- License: mit
- Created: 2024-08-24T08:19:46.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2024-08-24T11:56:32.000Z (2 months ago)
- Last Synced: 2024-08-24T12:46:46.679Z (2 months ago)
- Language: Go
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-echo-lambda-function-url-template
This is a template for publishing Go's Echo Web app with Lambda Function URL using Lambda Web Adapter.
## Requirements
* AWS CLI already configured with Administrator permission
* [Docker installed](https://www.docker.com/community-edition)
* SAM CLI - [Install the SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html)You may need the following for local testing.
* [Golang](https://golang.org)## Setup process
### Installing dependencies & building the target
In this example we use the built-in `sam build` to build a docker image from a Dockerfile and then copy the source of your application inside the Docker image.
Read more about [SAM Build here](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-build.html)### Local development
```shell
go run app/main.go
```If the previous command ran successfully you should now be able to hit the following local endpoint to invoke your function `http://localhost:8000/`
## Packaging and deployment
AWS Lambda Golang runtime requires a flat folder with the executable generated on build step. SAM will use `CodeUri` property to know where to look up for the application:
```yaml
...
FirstFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: app/
...
```To deploy your application for the first time, run the following in your shell:
```shell
sam deploy --guided
```The command will package and deploy your application to AWS, with a series of prompts:
* **Stack Name**: The name of the stack to deploy to CloudFormation. This should be unique to your account and region, and a good starting point would be something matching your project name.
* **AWS Region**: The AWS region you want to deploy your app to.
* **Confirm changes before deploy**: If set to yes, any change sets will be shown to you before execution for manual review. If set to no, the AWS SAM CLI will automatically deploy application changes.
* **Allow SAM CLI IAM role creation**: Many AWS SAM templates, including this example, create AWS IAM roles required for the AWS Lambda function(s) included to access AWS services. By default, these are scoped down to minimum required permissions. To deploy an AWS CloudFormation stack which creates or modifies IAM roles, the `CAPABILITY_IAM` value for `capabilities` must be provided. If permission isn't provided through this prompt, to deploy this example you must explicitly pass `--capabilities CAPABILITY_IAM` to the `sam deploy` command.
* **Save arguments to samconfig.toml**: If set to yes, your choices will be saved to a configuration file inside the project, so that in the future you can just re-run `sam deploy` without parameters to deploy changes to your application.You can find your API Gateway Endpoint URL in the output values displayed after deployment.
### Testing
We use `testing` package that is built-in in Golang and you can simply run the following command to run our tests locally:
```shell
go test ./app -v
```## Appendix
### Golang installation
Please ensure Go 1.x (where 'x' is the latest version) is installed as per the instructions on the official golang website: https://golang.org/doc/install
A quickstart way would be to use Homebrew, chocolatey or your linux package manager.
#### Homebrew (Mac)
Issue the following command from the terminal:
```shell
brew install golang
```If it's already installed, run the following command to ensure it's the latest version:
```shell
brew update
brew upgrade golang
```#### Chocolatey (Windows)
Issue the following command from the powershell:
```shell
choco install golang
```If it's already installed, run the following command to ensure it's the latest version:
```shell
choco upgrade golang
```## Bringing to the next level
Here are a few ideas that you can use to get more acquainted as to how this overall process works:
* Create an additional API resource (e.g. /hello/{proxy+}) and return the name requested through this new path
* Update unit test to capture that
* Package & DeployNext, you can use the following resources to know more about beyond hello world samples and how others structure their Serverless applications:
* [AWS Serverless Application Repository](https://aws.amazon.com/serverless/serverlessrepo/)