I am new to using AWS, and I am working on converting an ASP.NET application to a serverless architecture. One of the Lambda functions that I am trying to write is take an object and save it to a PostgreSQL database. Normally, I do this using Entity Framework, but seeing as to the limit in scope with Lambda functions, I am not sure how to use EF, if possible, with a Lambda function. Does anyone know if this is possible, and if so, how to use EF in a Lambda function?
I had a thought of trying to build a library hosted on CodeArtifact and import the models and context classes, but not sure if that is good or viable idea or now. Thoughts on that? Or would anyone recommended a different approach?
Edit: If you can't use EF in Lambda, any recommendations on best practice for using Lambda to send data to a database?
Thanks!
In case anyone is wondering the same thing I asked earlier, I just finished working this and found a solution. This is what I did, hopefully this helps!
First I built a helper library that contained the models and DbContexts that I wanted to use in my Lambda function. I did it this way because I want to use the same models across a few other Lambda's in the future. I published it as a local NuGet package. This will eventually be stored in AWS Code Artifact.
Started a new Lambda project in VS2019 using the AWS Toolkit, using the .NET5 Container image template. I imported the local NuGet helper library into the project.
I set up the DbContext on the library with a constructor to take a connection string (this is imported from a JSON stored on an S3 bucket). In the Lambda, I call the API like you normally would, parse the response into the DbContext models and then save the changes.
After uploading the completed Lambda, I use an EventBridge to schedule the Lambda to fire once every 24 hours.
Let me know if you need more details, and I can try and write out a longer explanation.