Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduction of AWS Lambda Web Adapter #31

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .aws-sam/build.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This file is auto generated by SAM CLI build command

[function_build_definitions]

[layer_build_definitions]
16 changes: 16 additions & 0 deletions app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM public.ecr.aws/sam/build-java17:1.108.0-20240123221230 as build-image
WORKDIR "/task"
COPY src src/
COPY gradle gradle/
COPY gradlew ./
COPY gradlew.bat ./
COPY build.gradle ./
COPY settings.gradle ./
RUN ./gradlew clean assemble

FROM public.ecr.aws/docker/library/amazoncorretto:17.0.10-alpine3.19
COPY --from=public.ecr.aws/awsguru/aws-lambda-adapter:0.8.1 /lambda-adapter /opt/extensions/lambda-adapter
EXPOSE 8080
WORKDIR /opt
COPY --from=build-image /task/build/libs/mrls-2.0.0.jar /opt
CMD ["java", "-jar", "mrls-2.0.0.jar"]
23 changes: 21 additions & 2 deletions build.gradle → app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.0.1'
id 'org.springframework.boot' version '3.2.2'
id 'io.spring.dependency-management' version '1.1.0'
}

group = 'io.github.tttol'
version = "1.1.6"
version = "2.0.0"
sourceCompatibility = '17'

configurations {
Expand All @@ -32,3 +32,22 @@ dependencies {
tasks.named('test') {
useJUnitPlatform()
}

// sourceSets {
// main {
// java {
// srcDirs = ['app/src/main/java']
// resources {
// srcDirs = ['app/src/main/resources']
// }
// }
// }
// test {
// java {
// srcDirs = ['app/src/test/java']
// resources {
// srcDirs = ['app/src/test/resources']
// }
// }
// }
// }
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.github.tttol.mrls.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import lombok.RequiredArgsConstructor;

@Controller
@RequestMapping("/")
@RequiredArgsConstructor
public class TopController {
@GetMapping
public String top() {
return "top";
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
server:
port: 8081
app:
gitlab:
host: ${GITLAB_HOST}
host: host
project:
id: ${GITLAB_PROJECT_ID}
accessToken: ${GITLAB_ACCESS_TOKEN}
id: id
accessToken: token
api:
endpoint: https://${app.gitlab.host}/api/v4/projects/${app.gitlab.project.id}/merge_requests?state=opened
logging:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
</td>
</tr>
</table>
<div class="appVer">1.1.7</div>
<div class="appVer">2.0.0</div>
</main>
<!-- <div th:replace="fragment/footer::footer"></div>-->
</body>
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/resources/templates/top.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>MRLS</title>
<link rel="icon"
href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text x=%2250%%22 y=%2250%%22 style=%22dominant-baseline:central;text-anchor:middle;font-size:90px;%22>😎</text></svg>">
</head>
<body>
<h1>Hello MRLS</h1>
</body>
</html>
75 changes: 75 additions & 0 deletions template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
mrls in AWS Lambda
Globals:
Function:
Timeout: 10

Resources:
MrlsFunction:
Type: AWS::Serverless::Function
Properties:
PackageType: Image
MemorySize: 2048
Tracing: Active
Environment:
Variables:
RUST_LOG: info
READINESS_CHECK_PATH: /healthz
REMOVE_BASE_PATH: /v1
AutoPublishAlias: live
DeploymentPreference:
Type: AllAtOnce
ProvisionedConcurrencyConfig:
ProvisionedConcurrentExecutions: 1
Events:
Root:
Type: HttpApi
Properties:
Path: /v1
Method: ANY
Mrls:
Type: HttpApi
Properties:
Path: /v1/{proxy+}
Method: ANY
# Metadata:
# DockerTag: java17.gradle-v1
# DockerContext: ./app
# Dockerfile: Dockerfile

MyScalableTarget:
Type: AWS::ApplicationAutoScaling::ScalableTarget
Properties:
MaxCapacity: 100
MinCapacity: 1
ResourceId: !Sub function:${MrlsFunction}:live # You need to specify an alis or version here
RoleARN: !Sub arn:aws:iam::${AWS::AccountId}:role/aws-service-role/lambda.application-autoscaling.amazonaws.com/AWSServiceRoleForApplicationAutoScaling_LambdaConcurrency
ScalableDimension: lambda:function:ProvisionedConcurrency
ServiceNamespace: lambda
DependsOn: MrlsFunctionAliaslive # This is your function logical ID + "Alias" + what you use for AutoPublishAlias

MyTargetTrackingScalingPolicy:
Type: AWS::ApplicationAutoScaling::ScalingPolicy
Properties:
PolicyName: utilization
PolicyType: TargetTrackingScaling
ScalingTargetId: !Ref MyScalableTarget
TargetTrackingScalingPolicyConfiguration:
TargetValue: 0.70 # Any value between 0 and 1 can be used here
CustomizedMetricSpecification:
Dimensions:
- Name: FunctionName
Value: !Ref MrlsFunction
- Name: Resource
Value: !Sub "${MrlsFunction}:live"
MetricName: ProvisionedConcurrencyUtilization
Namespace: AWS/Lambda
Statistic: Maximum
Unit: Count

Outputs:
MrlsApi:
Description: "API Gateway endpoint URL for Prod stage for Mrls function"
Value: !Sub "https://${ServerlessHttpApi}.execute-api.${AWS::Region}.${AWS::URLSuffix}/v1/mrls"
1 change: 0 additions & 1 deletion version.properties

This file was deleted.

Loading