https://github.com/anjasfedo/go-aws-lambda
Simple AWS Lambda Function Written in Go
https://github.com/anjasfedo/go-aws-lambda
aws-lambda golang learning-by-doing
Last synced: 2 months ago
JSON representation
Simple AWS Lambda Function Written in Go
- Host: GitHub
- URL: https://github.com/anjasfedo/go-aws-lambda
- Owner: Anjasfedo
- Created: 2024-01-19T13:47:12.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-01-19T14:24:31.000Z (almost 2 years ago)
- Last Synced: 2025-01-17T03:28:28.958Z (12 months ago)
- Topics: aws-lambda, golang, learning-by-doing
- Language: Go
- Homepage:
- Size: 5.08 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# AWS Lambda Go Application :zap:
This repository contains a simple AWS Lambda function written in Go. The Lambda function receives an event, processes it, and returns a response. The function is triggered by the AWS Lambda service.
## Overview :mag_right:
The Lambda function takes an event of type `MyEvent` with fields "Name" and "Age" and responds with a message indicating the provided name and age.
### Input Event Structure
```json
{
"What is your name?": "Anjas",
"How old are you?": 20
}
```
### Output Response Structure
```json
{
"Answer: ": "Anjas is 20 years old"
}
```
## Code Explanation :rocket:
### `main.go`
The `main.go` file serves as the entry point for the AWS Lambda Go application.
- **Imports:**
The necessary packages are imported, including `fmt` for formatted I/O and `github.com/aws/aws-lambda-go/lambda` for AWS Lambda functionality.
- **Event Structures:**
Two structures, `MyEvent` and `MyResponse`, are defined to represent the input and output data formats for the Lambda function.
- **Handler Function:**
The `handleLambdaEvent` function processes the Lambda event and generates a response. It formats a message based on the provided name and age.
- **Main Function:**
The `main` function initiates the Lambda function by calling `lambda.Start()`, passing the `handleLambdaEvent` function as the handler.
## Usage :wrench:
Invoke the Lambda function with an event similar to the provided `MyEvent` structure:
```bash
aws lambda invoke --function-name YourLambdaFunctionName --payload '{"What is your name?": "Anjas", "How old are you?": 20}' output.json
```
## Closing Notes 📝
Feel free to adjust the configuration, and if you encounter any issues or have suggestions for improvement, please open an issue or submit a pull request.
Happy coding! 🤖👨💻