Apple Silicon M1, AWS SAM-CLI, Docker, MySql, and .netcore 3.1 lambdas.
The question everyone is asking!, Can I develop a .netcore 3.1 serverless application on a Mac M1 using AWS Amplify, SAM-CLI, MySql and Docker?
The short answer is YES, so if this was stopping you from buying an M1, you can stop reading and go to the apple website/store to get your M1.
Now, you have your new shiny M1 and need to make it work. Here is how:
Just download the silicon docker installer and follow the instructions. Make sure to install rosetta. https://docs.docker.com/docker-for-mac/apple-silicon/
softwareupdate — install-rosetta
Run on docker and pull the aarch64 MySql Version, no problems here.
sudo docker pull mysql/mysql-server:latest-aarch64
Download and install the mac x64 installer from the Microsoft website.
SAM-CLI & .netcore container.
First, Install SAM-CLI following the instructions from the AWS Website
Once installed, my first attempt was to do a sam init, select amazon/dotnetcore3.1-base from the AWS Quick Start Templates, and configure the generated template.yaml, which had worked on a Linux x64 machine, but after trying to run it on the M1 I got the following error:
qemu: uncaught target signal 6 (Aborted) — core dumped
15 Aug 2021 12:27:48,341 [WARN] (email@example.com:331 errno: None) run_dotnet(dotnet_path, &args) failed
END RequestId: aa2a3380-e709–45b5-acbb-50caa37450a5
REPORT RequestId: aa2a3380-e709–45b5-acbb-50caa37450a5 Init Duration: 0.96 ms Duration: 2357.92 ms Billed Duration: 2400 ms Memory Size: 5000 MB Max Memory Used: 5000 MB
Invalid lambda response received: Lambda response must be valid json
2021–08–15 07:27:48 127.0.0.1 — — [15/Aug/2021 07:27:48] “GET / HTTP/1.1” 502
The solution, after a few hours of googling, was to do my own template and create my own dockerfile using the following images from MS & AWS.
Edit => September 24 2021
After a few weeks, AWS updated their image, it stopped working and the error qemu: uncaught target signal 6 came up again. Solution: To reference an old aws lambda image in the dockerfile.
And Boom! When I ran sam build and sam local start-api it all worked.
Now, make sure you run sam local with warm containers, otherwise, each request provisions a new container and which can take 2 or 3 seconds. https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-local-start-api.html
sam local start-api --warm-containers LAZY
In summary, it is possible to run your local AWS-SAM + Amplify + .netcore Lambda + MySql environment on an Apple silicon M1. I still cannot debug with SAM, and you get the occasional qemu: uncaught target signal 6 (Aborted) — core dumped error when your application throws an operating system exception. One of them for instance is trying to obtain environment variables not set in your template.yaml.