aws-samples / aws-lambda-lifecycle-hooks-function

Using Auto Scaling lifecycle hooks, Lambda, and EC2 Run Command
Apache License 2.0
102 stars 61 forks source link

Can't use for AWS python 3.7 version #17

Open ivanchen88 opened 2 years ago

ivanchen88 commented 2 years ago

about this script from aws lambda can't use for python 3.7 version .. anyone can help ? thanks

{ "schemaVersion": "1.2", "description": "Backup logs to S3", "parameters": {}, "runtimeConfig": { "aws:runShellScript": { "properties": [ { "id": "0.aws:runShellScript", "runCommand": [ "", "ASGNAME='ASGBackup'", "LIFECYCLEHOOKNAME='ASGBackup'", "BACKUPDIRECTORY='/var/log'", "S3BUCKET=''", "INSTANCEID=$(curl http://169.254.169.254/latest/meta-data/instance-id)", "REGION=$(curl http://169.254.169.254/latest/meta-data/placement/availability-zone)", "REGION=${REGION::-1}", "SNSTARGET='arn:aws:sns:'${REGION}'::'",
"HOOKRESULT='CONTINUE'", "MESSAGE=''", "", "tar -cf /tmp/${INSTANCEID}.tar $BACKUPDIRECTORY &> /tmp/backup", "if [ $? -ne 0 ]", "then", " MESSAGE=$(cat /tmp/backup)", "else", " aws s3 cp /tmp/${INSTANCEID}.tar s3://${S3BUCKET}/${INSTANCEID}/ &> /tmp/backup", " MESSAGE=$(cat /tmp/backup)", "fi", "", "aws sns publish --subject 'ASG Backup' --message \"$MESSAGE\" --target-arn ${SNSTARGET} --region ${REGION}", "aws autoscaling complete-lifecycle-action --lifecycle-hook-name ${LIFECYCLEHOOKNAME} --auto-scaling-group-name ${ASGNAME} --lifecycle-action-result ${HOOKRESULT} --instance-id ${INSTANCEID} --region ${REGION}" ] } ] } } }

dylanmtaylor commented 2 years ago

Replace the exception lines with

except Exception as e: