This is a simple REST API written in GoLang that provides CRUD (Create, Read, Update, Delete) operations for managing player information. The data is stored in Amazon DynamoDB, and the API is deployed as an AWS Lambda function, accessible through the AWS API Gateway.
- Get All Players: Retrieve a list of all players stored in the DynamoDB table.
- Get Player by ID: Retrieve player information by providing the player's ID as a URL parameter.
- Create Player: Add a new player to the DynamoDB table by sending player information as a JSON object in the request body.
- Delete Player by ID: Delete a player from the DynamoDB table using the player's ID provided as a URL parameter.
- Update Player by ID: Update existing player information in the DynamoDB table using the player's ID provided as a URL parameter.
Each player record in the DynamoDB table consists of the following fields:
- id: Unique identifier for the player.
- firstName: First name of the player.
- lastName: Last name of the player.
- country: Country of the player.
- club: Current club or team of the player.
To use this API, you can interact with it by sending ID or data as URL parameters using HTTP requests. Below are the available endpoints:
HTTP Method | EndPoint | Description |
---|---|---|
GET | /staging | Retrieve all players. |
GET | /staging?id={ID} | Retrieve a player by ID. |
POST | /staging | Create a new player. |
PUT | /staging?id={ID} | Update a player by ID. |
DELETE | /staging?id={ID} | Delete a player by ID. |
GET /staging?id=b68c99b8-c770-412e-aff6-36aa977b563
{
"id":"b68c99b8-c770-412e-aff6-36aa977b563",
"firstName": "Lionel",
"lastName": "Messi",
"country": "arg",
"position": "FW",
"club": "Inter Miami"
}
GOOS=linux GOARCH=amd64 go build -tags lambda.norpc -o bootstrap main.go
zip -jrm myFunction.zip bootstrap
The API is deployed as an AWS Lambda function, integrated with the AWS API Gateway for access.
NOTE Ensure that appropriate permissions(execution roles)are set for the Lambda function to interact with DynamoDB.
Development To set up this project locally for development or testing purposes, follow these steps:
- Clone the repository.
- Install GoLang and required dependencies.
- Set up your AWS credentials and configure the AWS SDK v1 for GoLang.
- Customize the code as needed.
- Deploy the Lambda function and API Gateway using the AWS CLI or preferred deployment method.
The complete guide can be found in this article.