Trying to run docker container using.net core lambda image

Viewed 30

I have a simple C# function that I want to deploy to lambda as a container image

My Function

using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;

using Amazon.Lambda.APIGatewayEvents;
using Amazon.Lambda.Core;
using MySql.Data.MySqlClient;

//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 HelloWorld
{

    public class Function
    {
        public async Task<APIGatewayProxyResponse> FunctionHandler(APIGatewayProxyRequest apigProxyEvent, ILambdaContext context)
        {
            string connStr = //hidden;
            MySqlConnection conn = new MySqlConnection(connStr);
            ArrayList objs = new ArrayList();
            var s = context.LogGroupName;
            
            
            try
            {
                
                conn.Open();

                string sql = "SELECT * FROM sys.ALM_AGGR_LQ_201231_210111_0600_A048_V3_75_GAI LIMIT 2";
                MySqlCommand cmd = new MySqlCommand(sql, conn);
                MySqlDataReader rdr = cmd.ExecuteReader();
                
                while (rdr.Read())
                {
                    objs.Add(new
                    {
                        aggr_grp_no = rdr["aggr_grp_no"],
                        source_rowno = rdr["source_rowno"]
                    });
                }
                rdr.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            

            conn.Close();
            
            
            
            
            return new APIGatewayProxyResponse
            {
                Body = "sefse",
                StatusCode = 200,
                Headers = new Dictionary<string, string> { { "Content-Type", "application/json" } }
            };

        }
    }
}

My Dockerfile

FROM public.ecr.aws/lambda/dotnet:core3.1.2022.08.17.17
#You can alternately also pull these images from DockerHub amazon/aws-lambda-dotnet:6

# Copy function code
COPY src/HelloWorld/Function.cs ${LAMBDA_TASK_ROOT}

# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile)
CMD [ "HelloWorld::HelloWorld.Function::FunctionHandler" ]

I follow the instructions here to test my container locally

first I build my image.

docker build -t dotnet-container .

I spin up a container

docker run -p 9000:8080 dotnet-container

I send a curl request

curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"payload":"hello world!"}'

However, this gives me the following error

{
  "errorType": "LambdaException",
  "errorMessage": "Could not find the required 'HelloWorld.deps.json'.  This file should be present at the root of the deployment package."
}

In none of the tutorial I looked at on aws website this HelloWorld.deps.json is mentioned, can anyone shed some light on what that is?

0 Answers
Related