Presenting a simple template to develop, publish, and test a simple C# service backend on AWS, with serverless Lambda functions, supported by DynamoDb, behind an API Gateway, and protected by Cognito auth.
Hopefully this will accelerate some early prototyping for some of my projects, and perhaps you’ll find it useful as a reference too.
UPDATE: errata
2023-03-18. I’ve recently backported a few fixes into the template:
- The APIs currently require the user’s identity token. It’s preferable to use an access token.
- Instead of activating the first use / password reset process, AWS permits us to directly set the test user password.
- Cross-origin requests are rejected by browsers because CORS headers aren’t available.
- CORS headers are also required for 4XX errors from the Cognito authorizer, and 5XX from lambda execution.
The rocketship template
I’ve been giving some thought to building a number of prototype projects for some friends. They need to reflect the realities of hosting on a cloud service provider, exploit the benefits of serverless design, and offer some frequently needed services: serverless lambdas with database support, behind an API gateway protected by an authentication service.
What I came up with is probably not too surprising, given the brief…
It’s a nice design, it’s pretty simple, and it suits a variety of applications. You’re welcome to plunder it on GitHub:
Scripts and instructions for setup, building and testing a deployment are included with the repository.
Some notes
Zones (DMZ and Services) and connections between services here are implemented through IAM access controls.
I instinctively work in C# by default, and that’s what I’ve used for the sample functions in the template. It doesn’t need to be .NET services, and you can swap them out for anything else.
I’ve not implemented any kind of client yet. I’ve had some good results using Blazor webasm in the past, but you may have a cool javascript or TS framework of your own in mind.
If you make improvements and amendments, do please upstream a PR or two!