GitXplorerGitXplorer
g

lambda-annotations-sample

public
3 stars
1 forks
1 issues

Commits

List of commits on branch main.
Unverified
a8e1bd137c19b0c49ef025a122b5c7216231d7a3

update annotations package version

committed 3 years ago
Unverified
42e3c440c6fe3a56fb2c65e38d59badeb18df95f

fixed interface

committed 3 years ago
Unverified
6826a35126e22621abd4c9c55c8edc6c3f7ed9d2

remove root redundant dir

committed 3 years ago
Unverified
f1947e8e114ff872fbb8f5e90bb110252fe68135

move readme at root

committed 3 years ago
Unverified
bc1bf4ef4604b71d0d147b8d40e0790607304d73

initial commit

committed 3 years ago

README

The README file for this repository.

Empty AWS Serverless Application Project

This starter project consists of:

  • serverless.template - An AWS CloudFormation Serverless Application Model template file for declaring your Serverless functions and other AWS resources
  • Function.cs - Class file containing the C# method mapped to the single function declared in the template file
  • aws-lambda-tools-defaults.json - Default argument settings for use within Visual Studio and command line deployment tools for AWS

You may also have a test project depending on the options selected.

The generated project contains a Serverless template declaration for a single AWS Lambda function that will be exposed through Amazon API Gateway as a HTTP Get operation. Edit the template to customize the function or add more functions and other resources needed by your application, and edit the function code in Function.cs. You can then deploy your Serverless application.

Packaging as a Docker image.

This project is configured to package the Lambda function as a Docker image. The default configuration for the project and the Dockerfile is to build the .NET project on the host machine and then execute the docker build command which copies the .NET build artifacts from the host machine into the Docker image.

The --docker-host-build-output-dir switch, which is set in the aws-lambda-tools-defaults.json, triggers the AWS .NET Lambda tooling to build the .NET project into the directory indicated by --docker-host-build-output-dir. The Dockerfile has a COPY command which copies the value from the directory pointed to by --docker-host-build-output-dir to the /var/task directory inside of the image.

Alternatively the Docker file could be written to use multi-stage builds and have the .NET project built inside the container. Below is an example of building the .NET project inside the image.

FROM public.ecr.aws/lambda/dotnet:6 AS base

FROM mcr.microsoft.com/dotnet/sdk:6.0-bullseye-slim as build
WORKDIR /src
COPY ["LambdaAnnotationsSample.csproj", "LambdaAnnotationsSample/"]
RUN dotnet restore "LambdaAnnotationsSample/LambdaAnnotationsSample.csproj"

WORKDIR "/src/LambdaAnnotationsSample"
COPY . .
RUN dotnet build "LambdaAnnotationsSample.csproj" --configuration Release --output /app/build

FROM build AS publish
RUN dotnet publish "LambdaAnnotationsSample.csproj" \
            --configuration Release \ 
            --runtime linux-x64 \
            --self-contained false \ 
            --output /app/publish \
            -p:PublishReadyToRun=true  

FROM base AS final
WORKDIR /var/task
COPY --from=publish /app/publish .

When building the .NET project inside the image you must be sure to copy all of the class libraries the .NET Lambda project is depending on as well before the dotnet build step. The final published artifacts of the .NET project must be copied to the /var/task directory. The --docker-host-build-output-dir switch can also be removed from the aws-lambda-tools-defaults.json to avoid the .NET project from being built on the host machine before calling docker build.

Here are some steps to follow from Visual Studio:

To deploy your Serverless application, right click the project in Solution Explorer and select Publish to AWS Lambda.

To view your deployed application open the Stack View window by double-clicking the stack name shown beneath the AWS CloudFormation node in the AWS Explorer tree. The Stack View also displays the root URL to your published application.

Here are some steps to follow to get started from the command line:

Once you have edited your template and code you can deploy your application using the Amazon.Lambda.Tools Global Tool from the command line.

Install Amazon.Lambda.Tools Global Tools if not already installed.

    dotnet tool install -g Amazon.Lambda.Tools

If already installed check if new version is available.

    dotnet tool update -g Amazon.Lambda.Tools

Execute unit tests

    cd "LambdaAnnotationsSample/test/LambdaAnnotationsSample.Tests"
    dotnet test

Deploy application

    cd "LambdaAnnotationsSample/src/LambdaAnnotationsSample"
    dotnet lambda deploy-serverless