5

I have been trying to use packer to create an AMI from Lambda for a particular use case. I am using bash custom runtime environment. I pulled the packer package and unzipped it.

But when I try to run the executable, Lambda throws me out with exit status 1 and the error is not descriptive too. I tried to fix this in a few ways-

  1. Add packer dir path to $PATH, but I am unable to source the .profile or .bashrc, it says they dont exist.

  2. Tried adding a layer with packer executable to Lambda, still does not help.

Code -

    echo "Installing Packer..."
    curl -qL -o packer.zip https://releases.hashicorp.com/packer/1.1.1/packer_1.1.1_linux_amd64.zip
    echo "Unzipping Packer"
    unzip packer.zip
    echo "Changing permissions on packer"
    chmod 777 ./packer
    echo "Running Packer Validate"
    ./packer validate ${LAMBDA_TASK_ROOT}/packer.json

Lambda Console log -

    % Total    % Received % Xferd  Average Speed   Time    Time     
    Time  Current Dload  Upload   Total   Spent    Left  Speed

    0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
    100 15.8M  100 15.8M    0     0  48.3M      0 --:--:-- --:--:-- --:--:-- 49.2M
    END RequestId: 14cb72cf-c7ff-4a4d-a1c1-99d145395aef
    REPORT RequestId: 14cb72cf-c7ff-4a4d-a1c1-99d145395aef  Init 
    Duration: 61.04 ms  Duration: 5623.92 ms    Billed Duration: 5700 ms    Memory Size: 1408 MB    Max Memory Used: 274 MB 
    RequestId: 14cb72cf-c7ff-4a4d-a1c1-99d145395aef Error: Runtime 
    exited with error: exit status 1
    Runtime.ExitError

On a side note, is there anything that can be done to have lambda logs be more descriptive? It does not even print out echo statements if the execution fails?

Has anyone been in this situation before? Any leads would help.

Thanks in advance for the help :)

  • Can you copy/paste the exact text you get from the console log, and the source code to your Lambda function? – wjordan Mar 12 '19 at 04:33
  • This looks like an error after the `curl` command. A bunch of serverless frameworks allow for using Docker images. Does AWS Lambda allow using the Hashi Packer image, or is it still lagging behind on that kind of functionality? You could skip straight to the `packer validate` that way. – Matthew Schuchard Mar 12 '19 at 12:41
  • What is 'bash custom runtime environment' - do you have a setup script or documentation on this custom environment? Is `unzip` available in the environment, for example? Can you customize the bash options (e.g., add `bash -x` for command-trace output)? – wjordan Mar 12 '19 at 15:51

3 Answers3

2

Don't try to run Packer in Lambda, use AWS ECS Fargate and run the official docker image.

Rickard von Essen
  • 4,110
  • 2
  • 23
  • 27
1

The Lambda execution environment is mounted on a read-only filesystem, except for /tmp which provides 512mb of scratch space. Add cd /tmp to the start of your Bash script to manipulate the downloaded file within the temp folder.

wjordan
  • 19,770
  • 3
  • 85
  • 98
0

if you want to create AMI using lambda at a particular time like triggering lambda with cron job and take AMI backup of ec2 you can follow my blog :

https://knowihave.blogspot.com/2018/09/aws-auto-ami-backup-across-all-region.html

code also available on my git :

https://github.com/harsh4870/AWS-auto-ami-backup-across-all-region

here i have written code in node js and triggering lambda using the cloud watch. if you face any issue you can contact easiest way i found to take AMi backup using lambda

and with your error i would suggest to check path again and importing setting to lambda it cloud only path error otherwise share some your code screenshot so can help

Harsh Manvar
  • 27,020
  • 6
  • 48
  • 102
  • @ChandrasekharMalladi can you increase the time out of lambda ? and memory limit from lambda console and run again for tetsing. – Harsh Manvar Mar 12 '19 at 05:05
  • From the log, I dont see that memory or time is going out of limit, its pretty much in the zone. However, I gave it a shot and it does not help. – Chandrasekhar Malladi Mar 12 '19 at 05:16