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

feat: introduce dotnet6 lambda #84

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
17 changes: 17 additions & 0 deletions .github/workflows/ci-dotnet6-function.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: ci-dotnet6-function
on:
pull_request:
branches: ["main"]
paths:
- "src/dotnet/Function-dotnet6/**"
- "src/dotnet/Service/**"
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: build-dotnet-webapi
run: |
chmod +x -R ./scripts
./scripts/builds/dotnet/build-dotnet-app.sh "src/dotnet/Function-dotnet6" "csproj"
51 changes: 37 additions & 14 deletions .github/workflows/ci-infrastructure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,37 +53,49 @@ jobs:
dotnet tool install -g Amazon.Lambda.Tools
source ./scripts/aws/credentials/set-up-user-credentials.sh $AWS_REGION $AWS_ACCESS_KEY_ID $AWS_SECRET_ACCESS_KEY
./scripts/artifacts/lambda/dotnet/create-dotnet-lambda-artifact.sh $GITHUB_HEAD_REF $SERVICE_NAME src/dotnet/Function dotnet-function netcoreapp3.1 $BUCKET_NAME
upload-nodejs-lambda-artifact:
upload-dotnet6-lambda-artifact:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: create-nodejs-lambda-artifact
- name: create-dotnet-lambda-artifact
run: |
chmod +x -R ./scripts
dotnet tool install -g Amazon.Lambda.Tools
source ./scripts/aws/credentials/set-up-user-credentials.sh $AWS_REGION $AWS_ACCESS_KEY_ID $AWS_SECRET_ACCESS_KEY
./scripts/artifacts/lambda/nodejs/create-nodejs-lambda-artifact.sh $GITHUB_HEAD_REF $SERVICE_NAME src/nodejs/lambda $BUCKET_NAME
upload-python-lambda-artifact:
./scripts/artifacts/lambda/dotnet/create-dotnet-lambda-artifact.sh $GITHUB_HEAD_REF $SERVICE_NAME src/dotnet/Function-dotnet6 dotnet6-function net6.0 $BUCKET_NAME
upload-nodejs-lambda-artifact:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: create-python-lambda-artifact
- name: create-nodejs-lambda-artifact
run: |
chmod +x -R ./scripts
source ./scripts/aws/credentials/set-up-user-credentials.sh $AWS_REGION $AWS_ACCESS_KEY_ID $AWS_SECRET_ACCESS_KEY
./scripts/artifacts/lambda/python/create-python-lambda-artifact.sh $GITHUB_HEAD_REF $SERVICE_NAME src/python $BUCKET_NAME
upload-nodejs-server-docker-image:
./scripts/artifacts/lambda/nodejs/create-nodejs-lambda-artifact.sh $GITHUB_HEAD_REF $SERVICE_NAME src/nodejs/lambda $BUCKET_NAME
upload-python-lambda-artifact:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: upload-nodejs-server-docker-image
- name: create-python-lambda-artifact
run: |
chmod +x -R ./scripts
source ./scripts/aws/credentials/set-up-user-credentials.sh $AWS_REGION $AWS_ACCESS_KEY_ID $AWS_SECRET_ACCESS_KEY
source ./scripts/aws/ecr/authenticate-with-ecr.sh $AWS_REGION $AWS_ACCOUNT_ID
./scripts/docker/docker-build.sh Dockerfile.create-nodejs-server-image $ECR_NAME
./scripts/docker/docker-tag.sh $ECR_NAME $GITHUB_HEAD_REF $AWS_REGION $AWS_ACCOUNT_ID
./scripts/docker/docker-push.sh $ECR_NAME $GITHUB_HEAD_REF $AWS_REGION $AWS_ACCOUNT_ID
./scripts/aws/ecr/remove-untagged-images-from-ecr.sh $ECR_NAME $AWS_REGION
./scripts/artifacts/lambda/python/create-python-lambda-artifact.sh $GITHUB_HEAD_REF $SERVICE_NAME src/python $BUCKET_NAME
# upload-nodejs-server-docker-image:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2
# - name: upload-nodejs-server-docker-image
# run: |
# chmod +x -R ./scripts
# source ./scripts/aws/credentials/set-up-user-credentials.sh $AWS_REGION $AWS_ACCESS_KEY_ID $AWS_SECRET_ACCESS_KEY
# source ./scripts/aws/ecr/authenticate-with-ecr.sh $AWS_REGION $AWS_ACCOUNT_ID
# ./scripts/docker/docker-build.sh Dockerfile.create-nodejs-server-image $ECR_NAME
# ./scripts/docker/docker-tag.sh $ECR_NAME $GITHUB_HEAD_REF $AWS_REGION $AWS_ACCOUNT_ID
# ./scripts/docker/docker-push.sh $ECR_NAME $GITHUB_HEAD_REF $AWS_REGION $AWS_ACCOUNT_ID
# ./scripts/aws/ecr/remove-untagged-images-from-ecr.sh $ECR_NAME $AWS_REGION

download-branch-artifacts:
needs: upload-iac-artifact
runs-on: ubuntu-latest
Expand All @@ -103,7 +115,7 @@ jobs:
[
download-branch-artifacts,
upload-dotnet-webapi-lambda-artifact,
upload-nodejs-server-docker-image,
# upload-nodejs-server-docker-image,
upload-dotnet-lambda-artifact,
upload-nodejs-lambda-artifact,
upload-python-lambda-artifact,
Expand Down Expand Up @@ -195,6 +207,17 @@ jobs:
SERVICE_GROUP=$(echo "$GITHUB_HEAD_REF"|tr '/' '-')
FUNCTION_NAME="dev-$SERVICE_NAME-$SERVICE_GROUP-dotnet-function"
./tests/coldstarts/main.sh $AWS_ACCESS_KEY_ID $AWS_SECRET_ACCESS_KEY $AWS_REGION 20 1000 $FUNCTION_NAME "payload.json"
run-coldstart-tests-dotnet6-function:
needs: [run-performance-tests]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: run-coldstart-tests
run: |
chmod +x -R ./tests/coldstarts/*.sh
SERVICE_GROUP=$(echo "$GITHUB_HEAD_REF"|tr '/' '-')
FUNCTION_NAME="dev-$SERVICE_NAME-$SERVICE_GROUP-dotnet6-function"
./tests/coldstarts/main.sh $AWS_ACCESS_KEY_ID $AWS_SECRET_ACCESS_KEY $AWS_REGION 20 1000 $FUNCTION_NAME "payload.json"
run-coldstart-tests-nodejs:
needs: [run-performance-tests]
runs-on: ubuntu-latest
Expand Down
42 changes: 42 additions & 0 deletions src/dotnet/Function-dotnet6/Function.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System.Collections.Generic;
using System.Net;

using Amazon.Lambda.Core;
using Amazon.Lambda.APIGatewayEvents;
using Service;
using System.Threading.Tasks;

// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]

namespace Function
{
public class Function
{
private readonly IDependencyService _service;

public Function() : this(DependencyService.CreateInstance()) { }
public Function(IDependencyService service)
{
_service = service;
}


public async Task<APIGatewayProxyResponse> FunctionHandler(APIGatewayProxyRequest request, ILambdaContext context)
{
context?.Logger?.Log($@"DOTNET-6-FUNCTION LAMBDA EXECUTION
request-id: {request?.RequestContext?.RequestId}
aws-request-id: {context?.AwsRequestId}");

var dependencyResponse = await _service.DoAsync();
var response = new APIGatewayProxyResponse
{
StatusCode = (int)HttpStatusCode.OK,
Body = $"dotnet-function-lambda {dependencyResponse}",
Headers = new Dictionary<string, string> { { "Content-Type", "text/plain" } }
};

return response;
}
}
}
20 changes: 20 additions & 0 deletions src/dotnet/Function-dotnet6/Function.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<AWSProjectType>Lambda</AWSProjectType>
<!-- This property makes the build directory similar to a publish directory and helps the AWS .NET Lambda Mock Test Tool find project dependencies. -->
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Amazon.Lambda.Core" Version="2.1.0" />
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.2.0" />
<PackageReference Include="Amazon.Lambda.APIGatewayEvents" Version="2.4.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Service\Service.csproj" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion src/dotnet/Function/Function.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public Function(IDependencyService service)

public async Task<APIGatewayProxyResponse> FunctionHandler(APIGatewayProxyRequest request, ILambdaContext context)
{
context?.Logger?.Log($@"DOTNET-FUNCTION LAMBDA EXECUTION
context?.Logger?.Log($@"DOTNET-3.1-FUNCTION LAMBDA EXECUTION
request-id: {request?.RequestContext?.RequestId}
aws-request-id: {context?.AwsRequestId}");

Expand Down
12 changes: 12 additions & 0 deletions terraform/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ locals {
timeout = 30
}
}
_dotnet_6_function = {
url = "dotnet6-function"
http_method = "GET"
config = {
function_name = "dotnet6-function"
s3_key = "artifacts/${var.service_name}/${var.service_version}/${var.service_name}-${var.service_version}-dotnet6-function.zip"
handler = "Function::Function.Function::FunctionHandler"
runtime = "dotnet6"
memory_size = 256
timeout = 30
}
}
_nodejs_function = {
url = "nodejs-function"
http_method = "GET"
Expand Down
3 changes: 1 addition & 2 deletions terraform/providers.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~>3.0"
source = "hashicorp/aws"
}
}
}
Expand Down