Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
341 views
in Technique[技术] by (71.8m points)

amazon web services - Bash MySQL Dump AWS Lambda

I'm attempting to create a lambda function that runs a bash file to mysqldump a db, gzip it, and move it to S3. I'm including a 'mysqldump' binary file in the zip because evidently the command is not available natively on the lambda server. I have a bootstrap file straight from the documentation and I'm able to echo all of my environment variables from a handler in my bash file:

handler () {
   set -e

   TIMEE=$(date +%Y-%m-%d-%H%M%S)

   echo "Backing up ${EXPORT_DB_NAME} to ${EXPORT_S3_PATH}/${EXPORT_DB_NAME}.sql using host: ${DB_HOST} and user: ${DB_USERNAME}"

   ./mysqldump --host ${DB_HOST} --opt -u ${DB_USERNAME} -p${DB_PASSWORD} ${EXPORT_DB_NAME} | gzip | aws s3 cp - s3://${EXPORT_S3_PATH}/${EXPORT_DB_FOLDER}/${EXPORT_DB_NAME}-$TIMEE.sql.gz
}

The error I'm getting:

{ "errorMessage": "RequestId: 22bc7a9f-6218-4872-a098-4d27918e4f1c Error: Runtime exited with error: exit status 127", "errorType": "Runtime.ExitError"

/var/task/export.sh: line 9: aws: command not found }

Looks like the aws command won't run -- why would the aws cli not work on the lambda function?

question from:https://stackoverflow.com/questions/66053187/bash-mysql-dump-aws-lambda

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I was able to get the aws command running inside the lambda function via 'layers' following the steps here. This immediately solved my problem and everything is working now.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...