diff --git a/.github/workflows/ci-dotnet6-function.yml b/.github/workflows/ci-dotnet6-function.yml new file mode 100644 index 0000000..4a0c195 --- /dev/null +++ b/.github/workflows/ci-dotnet6-function.yml @@ -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" + \ No newline at end of file diff --git a/.github/workflows/ci-infrastructure.yml b/.github/workflows/ci-infrastructure.yml index 29fc43e..31ed958 100644 --- a/.github/workflows/ci-infrastructure.yml +++ b/.github/workflows/ci-infrastructure.yml @@ -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 @@ -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, @@ -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 diff --git a/src/dotnet/Function-dotnet6/Function.cs b/src/dotnet/Function-dotnet6/Function.cs new file mode 100644 index 0000000..e2fce53 --- /dev/null +++ b/src/dotnet/Function-dotnet6/Function.cs @@ -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 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 { { "Content-Type", "text/plain" } } + }; + + return response; + } + } +} diff --git a/src/dotnet/Function-dotnet6/Function.csproj b/src/dotnet/Function-dotnet6/Function.csproj new file mode 100644 index 0000000..2cfc999 --- /dev/null +++ b/src/dotnet/Function-dotnet6/Function.csproj @@ -0,0 +1,20 @@ + + + net6.0 + true + Lambda + + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/dotnet/Function/Function.cs b/src/dotnet/Function/Function.cs index 7c62ae5..af72172 100644 --- a/src/dotnet/Function/Function.cs +++ b/src/dotnet/Function/Function.cs @@ -24,7 +24,7 @@ public Function(IDependencyService service) public async Task 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}"); diff --git a/terraform/locals.tf b/terraform/locals.tf index 2a8b023..4ec4cbe 100644 --- a/terraform/locals.tf +++ b/terraform/locals.tf @@ -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" diff --git a/terraform/providers.tf b/terraform/providers.tf index aba6afe..9996948 100644 --- a/terraform/providers.tf +++ b/terraform/providers.tf @@ -1,8 +1,7 @@ terraform { required_providers { aws = { - source = "hashicorp/aws" - version = "~>3.0" + source = "hashicorp/aws" } } }