gkrizek / bash-lambda-layer

Run Bash scripts in AWS Lambda via Layers
MIT License
428 stars 89 forks source link

Can't run all aws commands #42

Closed jimjy98 closed 5 years ago

jimjy98 commented 5 years ago

I am having some problems with regular aws commands. For example, I just try to run a bash script with the following content

function handler () {
    set -e

    aws configure set aws_access_key_id keyId
    aws configure set aws_secret_access_key secretAccessKey

    files=(`aws s3 ls s3://bucketName/ --recursive | awk '{print $4}'`)
}

Of course the key id and secret access key are valid keys. I just want to save the list of files in an s3 bucket to some variable files. However, I always get the same Runtime.ExitError with status code 255: Read-only file system: '/home/sbx_user1051'. Am I doing anything wrong?

gkrizek commented 5 years ago

This is a problem with the $HOME directory. The only writeable directory in Lambda is /tmp and those aws commands are trying to edit files in /home/sbx_user1051. In my bootstrap I set $HOME=/tmp, but it doesn't seem to carry through to the executions.

Can you try setting $HOME=/tmp yourself in your code?

If that doesn't work you can try to export those ids as environment variables as well. Like:

export AWS_ACCESS_KEY="keyId"
jimjy98 commented 5 years ago

Neither work. $HOME is an unbound variable for some reason, and $HOME in a local bash session usually reads a line from pwd to get its value. I also tried using environment variables for the access keys, but I am getting the same error The provided token is malformed or otherwise invalid.