Skip to content

Commit

Permalink
initial commit of aws-lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli committed Nov 22, 2023
1 parent 67fca10 commit 7e8a3d0
Show file tree
Hide file tree
Showing 55 changed files with 2,024 additions and 678 deletions.
43 changes: 43 additions & 0 deletions aws-lambda-project/.github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: CI Build

on:
push:
branches:
- "**"

jobs:
build:
name: Build
runs-on: ubuntu-latest
strategy:
matrix:
distribution: [ 'temurin' ]
java: [ '17' ]
steps:
- uses: actions/checkout@v3

- name: Setup Java 17
uses: actions/setup-java@v3
with:
java-version: ${{ matrix.java }}
distribution: ${{ matrix.distribution }}
cache: 'maven'

- name: Grant execute permission for mvnw
run: chmod +x mvnw

- name: Build with Maven
run: ./mvnw clean verify

- if: ${{ github.ref == 'refs/heads/main' }}
name: SonarQube Scan
run: ./mvnw compile sonar:sonar -Dsonar.login=${{ secrets.SONAR_TOKEN }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- if: ${{ github.ref == 'refs/heads/main' }}
name: Build and Publish Docker Image
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
./mvnw spring-boot:build-image -Dspring-boot.build-image.imageName=${{ secrets.DOCKER_USERNAME }}/aws-lambda-project
docker push ${{ secrets.DOCKER_USERNAME }}/aws-lambda-project
11 changes: 11 additions & 0 deletions aws-lambda-project/.localstack/01_init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

awslocal s3 mb s3://testbucket
echo "List of S3 buckets:"
echo "-------------------------------"
awslocal s3 ls

awslocal sqs create-queue --queue-name test_queue
echo "List of SQS Queues:"
echo "-------------------------------"
awslocal sqs list-queues
34 changes: 0 additions & 34 deletions aws-lambda-project/.localstack/init-aws.sh

This file was deleted.

Binary file modified aws-lambda-project/.mvn/wrapper/maven-wrapper.jar
Binary file not shown.
15 changes: 15 additions & 0 deletions aws-lambda-project/.yo-rc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"generator-springboot": {
"appName": "aws-lambda-project",
"packageName": "com.learning.awslambda",
"databaseType": "postgresql",
"dbMigrationTool": "liquibase",
"dbMigrationFormat": "xml",
"features": [
"localstack"
],
"buildTool": "maven",
"packageFolder": "com/learning/awslambda",
"liquibaseMigrationCounter": 2
}
}
14 changes: 14 additions & 0 deletions aws-lambda-project/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM eclipse-temurin:17.0.9_9-jre-focal as builder
WORKDIR application
ARG JAR_FILE=target/aws-lambda-project-0.0.1-SNAPSHOT.jar
COPY ${JAR_FILE} application.jar
RUN java -Djarmode=layertools -jar application.jar extract

# the second stage of our build will copy the extracted layers
FROM eclipse-temurin:17.0.9_9-jre-focal
WORKDIR application
COPY --from=builder application/dependencies/ ./
COPY --from=builder application/spring-boot-loader/ ./
COPY --from=builder application/snapshot-dependencies/ ./
COPY --from=builder application/application/ ./
ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"]
19 changes: 19 additions & 0 deletions aws-lambda-project/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
pipeline {
agent any

triggers {
pollSCM('* * * * *')
}

environment {
APPLICATION_NAME = 'aws-lambda-project'
}

stages {
stage('Build') {
steps {
sh './mvnw clean verify'
}
}
}
}
35 changes: 33 additions & 2 deletions aws-lambda-project/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,33 @@
# aws-lambda

# aws-lambda-project

### Format code

```shell
$ ./mvnw spotless:apply
```

### Run tests

```shell
$ ./mvnw clean verify
```

### Run locally

```shell
$ docker-compose -f docker/docker-compose.yml up -d
$ ./mvnw spring-boot:run -Dspring-boot.run.profiles=local
```

### Using Testcontainers at Development Time
You can run `TestApplication.java` from your IDE directly.
You can also run the application using Maven as follows:

```shell
./mvnw spring-boot:test-run
```


### Useful Links
* Swagger UI: http://localhost:8080/swagger-ui.html
* Actuator Endpoint: http://localhost:8080/actuator
35 changes: 17 additions & 18 deletions aws-lambda-project/docker/docker-compose-app.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
version: '3.8'
services:

aws-sqs-project:
build: ..
ports:
- "18080:8080"
- "18787:8787"
restart: always
depends_on:
- postgresqldb
- localstack
environment:
- SPRING_PROFILES_ACTIVE=docker
- SPRING_DATASOURCE_DRIVER_CLASS_NAME=org.postgresql.Driver
- SPRING_DATASOURCE_URL=jdbc:postgresql://postgresqldb:5432/appdb
- SPRING_DATASOURCE_USERNAME=siva
- SPRING_DATASOURCE_PASSWORD=secret
version: '3.8'
services:

aws-lambda-project:
build: ..
ports:
- "18080:8080"
- "18787:8787"
restart: always
depends_on:
- postgresqldb
environment:
- SPRING_PROFILES_ACTIVE=docker
- SPRING_DATASOURCE_DRIVER_CLASS_NAME=org.postgresql.Driver
- SPRING_DATASOURCE_URL=jdbc:postgresql://postgresqldb:5432/appdb
- SPRING_DATASOURCE_USERNAME=appuser
- SPRING_DATASOURCE_PASSWORD=secret
51 changes: 26 additions & 25 deletions aws-lambda-project/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
version: '3.8'
services:

postgresqldb:
image: postgres:16.1-alpine
environment:
- POSTGRES_USER=appuser
- POSTGRES_PASSWORD=secret
- POSTGRES_DB=appdb
ports:
- "5432:5432"

localstack:
image: localstack/localstack:3.0.0
ports:
- "127.0.0.1:4566:4566" # LocalStack Gateway
- "127.0.0.1:4510-4559:4510-4559" # external services port range
environment:
- DEBUG=${DEBUG-}
- DOCKER_HOST=unix:///var/run/docker.sock
- SERVICES=lambda
volumes:
- "${LOCALSTACK_VOLUME_DIR:-./volume}:/var/lib/localstack"
- "/var/run/docker.sock:/var/run/docker.sock"
- "../.localstack:/etc/localstack/init/ready.d" # ready hook
version: '3.8'
services:

postgresqldb:
image: postgres:16.0-alpine
environment:
- POSTGRES_USER=appuser
- POSTGRES_PASSWORD=secret
- POSTGRES_DB=appdb
ports:
- "5432:5432"

localstack:
image: localstack/localstack:2.3.2
ports:
- "4566:4566"
environment:
- SERVICES=s3,sqs
- DEFAULT_REGION=us-east-1
- DOCKER_HOST=unix:///var/run/docker.sock
- USE_SSL=0
- AWS_CBOR_DISABLE=1
volumes:
- "${LOCALSTACK_VOLUME_DIR:-./volume}:/var/lib/localstack"
- "/var/run/docker.sock:/var/run/docker.sock"
- "../.localstack:/etc/localstack/init/ready.d" # ready hook
1 change: 1 addition & 0 deletions aws-lambda-project/lombok.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lombok.addLombokGeneratedAnnotation = true
Loading

0 comments on commit 7e8a3d0

Please sign in to comment.