By Brian Fitzgerald
Introduction
aws lambda publish-layer-version fails silently. Out of memory is the root cause. Changing the instance type fixes the problem.
Symptoms
aws lambda publish-layer-version produces no output. The exit status is nonzero.
[root@ip-172-31-62-89 layers]# aws lambda publish-layer-version --layer-name oracle-instant-client-layer --zip-file fileb://oracle-instant-client-layer.zip --compatible-runtimes python3.7 [root@ip-172-31-62-89 layers]# echo $? 255
Investigation
Investigation using strace reveals an out of memory condition
[root@ip-172-31-62-89 layers]# uname -a Linux ip-172-31-62-89.ec2.internal 4.14.186-146.268.amzn2.x86_64 #1 SMP Tue Jul 14 18:16:52 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux [root@ip-172-31-62-89 layers]# strace -f -o tr aws lambda publish-layer-version --layer-name oracle-instant-client-layer --zip-file fileb://oracle-instant-client-layer.zip --compatible-runtimes python3.7 [root@ip-172-31-62-89 layers]# grep ENOMEM tr 3576 mmap(NULL, 272371712, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = -1 ENOMEM (Cannot allocate memory) 3576 mmap(NULL, 272502784, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = -1 ENOMEM (Cannot allocate memory)
The instance type is t2.micro. Physical memory is 983 MB
[root@ip-172-31-62-89 layers]# curl -X GET http://169.254.169.254/latest/meta-data/instance-type t2.micro[root@ip-172-31-62-89 layers]#
[root@ip-172-31-62-89 layers]# free -m
total used free shared buff/cache available
Mem: 983 63 742 0 177 784
Swap: 0 0 0
Solution
Change the instance type to t2.small. Re-run the command, The normal json output appears. The exit status is 0.
[root@ip-172-31-62-89 layers]# aws lambda publish-layer-version --layer-name oracle-instant-client-layer --zip-file fileb://oracle-instant-client-layer.zip --compatible-runtimes python3.7
{
"LayerVersionArn": "arn:aws:lambda:us-east-1:999999999999:layer:oracle-instant-client-layer:2",
"Description": "",
"CreatedDate": "2020-08-02T21:03:38.787+0000",
"LayerArn": "arn:aws:lambda:us-east-1:999999999999:layer:oracle-instant-client-layer",
"Content": {
"CodeSize": 51069060,
"CodeSha256": "B1DGnA385aL50A8mrKoq1FOsIsEtMerbhdYCwd485YA=",
"Location": "https://prod-04-2014-layers. etc."
},
"Version": 2,
"CompatibleRuntimes": [
"python3.7"
]
}
[root@ip-172-31-62-89 layers]# echo $?
0
Physical memory us 1991 MB.
[root@ip-172-31-62-89 layers]# curl -X GET http://169.254.169.254/latest/meta-data/instance-type
t2.small
[root@ip-172-31-62-89 layers]# free -m
total used free shared buff/cache available
Mem: 1991 63 1712 0 215 1788
Swap: 0 0 0
Conclusion
An AWS CLI on EC2 produced no output and exited silently. Investigation uncovered an out of memory condition, which was fixed by upgrading the instance type.
