Skip to content

Latest commit

 

History

10 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PowerLedger API hosted in AWS Lambda

A basic battery management application written with the Spring Boot 3 framework.

The application can be deployed to an AWS account using the Serverless Application Model. The template.yml file in the root folder contains the application definition.

The StreamLambdaHandler object is the main entry point for Lambda.

Pre-requisites

Local Deployment

  1. Build the application
./gradlew build
  1. Configure database access

Add your local PostgreSQL database credentials to resources/application.properties 3. Run the application

./gradlew bootRun

AWS Deployment (Prod, UAT & Sandbox)

  1. Have a PostgreSQL RDS instance running

You can do this from the AWS console or through a CloudFormation template.

Once that is done, update the resources/application.properties with your AWS credentials

  1. Update the AWS SAM template

Update the template.yml file in the root folder with your RDS instance's subnets and whitelisted security group.

  1. Build the application

In a shell, navigate to the sample's folder and use the SAM CLI to build a deployable package

sam build

This command compiles the application and prepares a deployment package in the .aws-sam sub-directory.

  1. Deploy the AWS

To deploy the application in your AWS account, you can use the SAM CLI's guided deployment process and follow the instructions on the screen

sam deploy --guided

Once the deployment is completed, the SAM CLI will print out the stack's outputs, including the new application URL. You can use curl or a web browser to make a call to the URL

...
---------------------------------------------------------------------------------------------------------
OutputKey-Description                        OutputValue
---------------------------------------------------------------------------------------------------------
PowerLedgerApi - URL for application            https://xxxxxxxxxx.execute-api.us-west-2.amazonaws.com/batteries
---------------------------------------------------------------------------------------------------------

$ curl https://xxxxxxxxxx.execute-api.us-west-2.amazonaws.com/batteries

API Endpoints

Create new batteries

Request

POST http://localhost:8080/batteries

Content-Type: application/json
Accept: application/json

Request body

[
  {
    "name": "Cannington",
    "postcode": "6107",
    "capacity": 13500
  },
  {
    "name": "Midland",
    "postcode": "6057",
    "capacity": 50500
  }
]

Response

[
    "ac861922-32df-4fec-8f20-5f66ad8b3159",
    "e9b88a2c-a537-4b64-86ab-c28c96d6696a"
]

Fetch many batteries and analytics

Request

Please note that both minPostcode and maxPostcode parameters are optional.

GET http://localhost:8080/batteries?minPostcode={value}&maxPostcode={value}

Accept: application/json

Response

{
    "count": 7,
    "totalCapacity": 176000,
    "averageCapacity": 25142,
    "batteries": [
        "Akunda Bay",
        "Hay Street",
        "Kent Town",
        "Norfolk Island",
        "Ootha",
        "University of Melbourne",
        "Werrington County"
    ]
}

Fetch a specific battery

Request

GET http://localhost:8080/batteries/{batteryId}

Accept: application/json

Response

{
  "id": "e9209313-0d86-4263-9b62-0b3ae4f7711a",
  "postcode": "6107",
  "name": "Cannington",
  "capacity": 13500,
  "createdAt": "2023-08-18T06:51:06.954978Z",
  "updatedAt": "2023-08-18T06:51:06.955047Z"
}

About

Spring Boot 3 REST API using AWS Lambda

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages