Try AWS Lambda Runtime Interface Emulator with Docker Desktop for M1

Hello, this is toyohama: birthday: Actually, I prepared another Christmas-like material, but when I tried to touch it, I suddenly thought, "Something like this, it looks like I'm wearing it ...", so I hurriedly tried to make it like the title. I did.

What to use this time

M1 Mac

I bought an M1 MacBook Air. I've used it for about a month, but it feels more like an iPad than an Intel Mac, including the hardware architecture. I installed Docker for this article and installed it for some reason, but it's very comfortable because it doesn't get very hot and doesn't work at all.

AWS Lambda Runtime Interface Emulator It is abbreviated as RIE. This or, This or, I think you can refer to the article on the net for details.

--You can now start containers on AWS Lambda ――What a 10GB image is OK ――Emulator was prepared (I think) because I couldn't upload such a heavy image for verification one by one.

So, RIE allows you to test whether the container can be started from Lambda on your machine.

Docker Desktop for M1 Do you like Docker? I love you. Now, all my personal development environment is built with Docker. I think it's okay to use a VM, but why are you so attracted to it? Maybe it's because it feels like a FreeBSD jail (personal impression).

It is rumored that M1 Mac will be officially supported in February 2021, but it will be possible to Preview version of Docker Desktop earlier than expected and Download without registration or application. became.


I tried to combine these and see if it works properly. I'm sure it's going to be thrown out because it's said that there's no such thing. .. While thinking.


Docker Desktop For M1 When you open dmg, it looks like this. It is a version called AppleSilicon-Preview7. スクリーンショット 2020-12-21 23.42.18.png

Deta! I wanted to see the characters of this PREVIEW once ..., dragging and dropping while raising the tension for a moment. スクリーンショット 2020-12-21 23.42.49.png

For some reason, the first startup did not become Docker Desktop is runnning, and I restarted it once, but after that it works normally.

AWS Lambda Runtime Interface Emulator

AWS official may be helpful. I wonder if there is no problem because aws-lambda-rie just copies the binary to the specified directory.

 $ mkdir -p ~/.aws-lambda-rie && curl -Lo ~/.aws-lambda-rie/aws-lambda-rie && chmod +x ~/.aws-lambda-rie/aws-lambda-rie
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   164  100   164    0     0    315      0 --:--:-- --:--:-- --:--:--   314
100   640  100   640    0     0    688      0 --:--:-- --:--:-- --:--:--   688
100 7964k  100 7964k    0     0  1230k      0  0:00:06  0:00:06 --:--:-- 1910k

 ~/.aws-lambda-rie $ ls -la
total 17120
drwxr-xr-x   3 toyohama  staff       96 12 21 23:19 .
drwxr-xr-x+ 15 toyohama  staff      480 12 21 23:19 ..
-rwxr-xr-x   1 toyohama  staff  8155136 12 21 23:19 aws-lambda-rie

Creating a sample




CMD ["app.lambda_handler"]

Since RIE is included as standard in the Docker image provided by AWS, it seems that an entry point for verification is included. Does that mean that the RIE I just installed had any meaning? I will proceed with the work while thinking.

def lambda_handler(event, context):
  message = "recieved data is {}".format(event['q'])
  return { 
    'message' : message

It's a very simple content, but for the time being, I thought I'd check if the thrown data would be returned properly. There is no deep meaning in choosing Python.

Container build

 $ docker build -t rie_python/latest .                        
[+] Building 31.7s (7/7) FINISHED                                                                                                                  
 => [internal] load build definition from Dockerfile                                                                                          0.4s
 => => transferring dockerfile: 124B                                                                                                          0.0s
 => [internal] load .dockerignore                                                                                                             0.5s
 => => transferring context: 2B                                                                                                               0.0s
 => [internal] load metadata for                                                                             3.5s
 => [1/2] FROM                      25.5s
 => => resolve                       0.0s
 => => sha256:313995d27e68d28fc879f28c24f3d13a185c083a1c41fef2d44afacfd03ff2dc 1.58kB / 1.58kB                                                0.0s
 => => sha256:eb3db1f34c3b76bc8614a677e26103ab66318b6a0b1af43064f47c33652881f5 2.89kB / 2.89kB                                                0.0s
 => => sha256:d519fd89485b556ac5741ddf554e274d7d2341df663202622ff0df17713b56ce 100.75MB / 100.75MB                                           16.0s
 => => sha256:c18accecece0cb85ff20fdb3dd2b221cc5d058e0cb3bae82e99218f26ac1d95f 417B / 417B                                                    1.0s
 => => sha256:6460572f426be4b5cfe45d592a01c053c74d1fce9478a8248f566217c3b5bd39 60.22kB / 60.22kB                                              2.0s
 => => sha256:03ac043af787c8cb06d6a7f8289c62cf97e630b08011717197ab2adb087d061d 3.31MB / 3.31MB                                                3.0s
 => => sha256:04f3d6691c40eabcab2a09fe0da44eb659d2d62fbf3f0770146c31d5ef39c339 54.41MB / 54.41MB                                             17.9s
 => => sha256:c5195ce15cfbc20ad941dec4a2f17da79f66a6bd054f99221c56c4b0551f858f 15.07MB / 15.07MB                                              7.8s
 => => extracting sha256:d519fd89485b556ac5741ddf554e274d7d2341df663202622ff0df17713b56ce                                                     1.5s
 => => extracting sha256:6460572f426be4b5cfe45d592a01c053c74d1fce9478a8248f566217c3b5bd39                                                     0.0s
 => => extracting sha256:c18accecece0cb85ff20fdb3dd2b221cc5d058e0cb3bae82e99218f26ac1d95f                                                     0.0s
 => => extracting sha256:03ac043af787c8cb06d6a7f8289c62cf97e630b08011717197ab2adb087d061d                                                     0.1s
 => => extracting sha256:04f3d6691c40eabcab2a09fe0da44eb659d2d62fbf3f0770146c31d5ef39c339                                                     1.6s
 => => extracting sha256:c5195ce15cfbc20ad941dec4a2f17da79f66a6bd054f99221c56c4b0551f858f                                                     0.8s
 => [internal] load build context                                                                                                             0.4s
 => => transferring context: 240B                                                                                                             0.0s
 => [2/2] COPY ./                                                                                                                      0.8s
 => exporting to image                                                                                                                        0.8s
 => => exporting layers                                                                                                                       0.5s
 => => writing image sha256:a20f98e9a887e4ff6c7c82b84b821135bedd16ca6911f26d2f0dfbf6782a5ef3                                                  0.0s
 => => naming to                                                                                                  0.0s


 $ docker run -p 9000:8080 rie_python/latest

Start by linking port9000 to 8080 of the container.

Try hitting from curl

 % curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{ "q":"Merry Christmas" }'                  

When I throw json toward the entry point prepared by RIE ...

That ... it went well ...

{"message": "recieved data is Merry Christmas"}% 

It came back properly ...


It's just an article that I tried RIE. I should have prepared something a little more ... Reflection.

However, I've only tried it with simple ones, so next time I'd like to move the image that was made with the x86 version.

Recommended Posts

Try AWS Lambda Runtime Interface Emulator with Docker Desktop for M1
Try connecting to AzureCosmosDB Emulator for Docker with Java
Try Oracle Enterprise Manager Cloud Control with Docker Desktop for Windows
Install Docker Desktop for Mac with Homebrew
Try local development of AWS (S3, DynamoDB) with AWS SDK for JavaScript and Docker
Try WildFly with Docker
Notify Slack of AWS bills daily with Lambda for Ruby
Build AWS Lambda with Quarkus
Try running SlackBot made with Ruby x Sinatra on AWS Lambda
(For myself) Try creating a C # environment with docker + code-server, cloud9
Run lambda with custom docker image
Environment construction with Docker for beginners
Try running cloudera manager with docker
Learn AWS for free with LocalStack
Memorandum of Understanding for Using Appium desktop Inspector with Emulator (Android App)