aws-samples / aws-lambda-lifecycle-hooks-function Goto Github PK
View Code? Open in Web Editor NEWUsing Auto Scaling lifecycle hooks, Lambda, and EC2 Run Command
License: Apache License 2.0
Using Auto Scaling lifecycle hooks, Lambda, and EC2 Run Command
License: Apache License 2.0
The output is the following:
/var/lib/amazon/ssm/i-0218f07a048432379/document/orchestration/2b726580-1b70-4f9e-8273-216627e6e45d/awsrunShellScript/0.awsrunShellScript/_script.sh: 8: /var/lib/amazon/ssm/i-0218f07a048432379/document/orchestration/2b726580-1b70-4f9e-8273-216627e6e45d/awsrunShellScript/0.awsrunShellScript/_script.sh: Bad substitution
failed to run commands: exit status 2
Though the backup procedure works, there is an error in the cloudwatch logs of the lambda function:
[ERROR] 2017-07-12T07:22:50.632Z e8984d42-66d2-11e7-a7af-510b0421530a Error: list index out of range
Here is the full log:
[DEBUG] 2017-07-12T07:22:49.907Z Loading JSON file: /var/runtime/botocore/data/endpoints.json
[DEBUG] 2017-07-12T07:22:50.31Z Loading JSON file: /var/runtime/botocore/data/ssm/2014-11-06/service-2.json
[DEBUG] 2017-07-12T07:22:50.64Z Loading JSON file: /var/runtime/botocore/data/_retry.json
[DEBUG] 2017-07-12T07:22:50.65Z Registering retry handlers for service: ssm
[DEBUG] 2017-07-12T07:22:50.68Z Event creating-client-class.ssm: calling handler <function add_generate_presigned_url at 0x7faf2e12e848>
[DEBUG] 2017-07-12T07:22:50.69Z The s3 config key is not a dictionary type, ignoring its value of: None
[DEBUG] 2017-07-12T07:22:50.70Z Setting ssm timeout as (60, 60)
START RequestId: e8984d42-66d2-11e7-a7af-510b0421530a Version: $LATEST
[INFO] 2017-07-12T07:22:50.71Z e8984d42-66d2-11e7-a7af-510b0421530a
{
"account": "350785128185",
"region": "us-east-1",
"detail": {
"LifecycleHookName": "ASGBackup",
"AutoScalingGroupName": "awseb-e-mam8pnazxz-stack-AWSEBAutoScalingGroup-1RRZHOXULUX78",
"LifecycleActionToken": "a860bb0a-3dfb-4cfc-b64f-86d228aea689",
"LifecycleTransition": "autoscaling:EC2_INSTANCE_TERMINATING",
"EC2InstanceId": "i-057beff453ba8887e"
},
"detail-type": "EC2 Instance-terminate Lifecycle Action",
"source": "aws.autoscaling",
"version": "0",
"time": "2017-07-12T07:22:48Z",
"id": "3e0b0358-9730-44c5-89a2-096e441c0c23",
"resources": [
"arn:aws:autoscaling:us-east-1:350785128185:autoScalingGroup:a8d17511-eec5-4b17-866b-ea0d5f1b0c36:autoScalingGroupName/awseb-e-mam8pnazxz-stack-AWSEBAutoScalingGroup-1RRZHOXULUX78"
]
}
[DEBUG] 2017-07-12T07:22:50.71Z e8984d42-66d2-11e7-a7af-510b0421530a Event before-parameter-build.ssm.ListDocuments: calling handler <function generate_idempotent_uuid at 0x7faf2e0e4d70>
[DEBUG] 2017-07-12T07:22:50.72Z e8984d42-66d2-11e7-a7af-510b0421530a Making request for OperationModel(name=ListDocuments) (verify_ssl=True) with params: {'body': '{"DocumentFilterList": [{"key": "Name", "value": "ASGLogBackup"}]}', 'url': u'https://ssm.us-east-1.amazonaws.com/', 'headers': {'User-Agent': 'Boto3/1.4.4 Python/2.7.12 Linux/4.4.51-40.60.amzn1.x86_64 exec-env/AWS_Lambda_python2.7 Botocore/1.5.52', 'Content-Type': u'application/x-amz-json-1.1', 'X-Amz-Target': u'AmazonSSM.ListDocuments'}, 'context': {'auth_type': None, 'client_region': 'us-east-1', 'has_streaming_input': False, 'client_config': <botocore.config.Config object at 0x7faf2de34390>}, 'query_string': '', 'url_path': '/', 'method': u'POST'}
[DEBUG] 2017-07-12T07:22:50.72Z e8984d42-66d2-11e7-a7af-510b0421530a Event request-created.ssm.ListDocuments: calling handler <bound method RequestSigner.handler of <botocore.signers.RequestSigner object at 0x7faf2de34290>>
[DEBUG] 2017-07-12T07:22:50.72Z e8984d42-66d2-11e7-a7af-510b0421530a Event choose-signer.ssm.ListDocuments: calling handler <function set_operation_specific_signer at 0x7faf2e0e4c80>
[DEBUG] 2017-07-12T07:22:50.73Z e8984d42-66d2-11e7-a7af-510b0421530a Calculating signature using v4 auth.
[DEBUG] 2017-07-12T07:22:50.76Z e8984d42-66d2-11e7-a7af-510b0421530a CanonicalRequest:
POST
/
content-type:application/x-amz-json-1.1
host:ssm.us-east-1.amazonaws.com
x-amz-date:20170712T072250Z
x-amz-security-token:FQoDYXdzELn//////////wEaDHM/oDkHT6rjH9WwOSLmAeFeEyc0+90TM2MhGBO5LPWOa1/fhPFpanPE0aLyIOsVnuvk8EbiGObL/t2zL8YMeVWJNsNB4F1StC9Z7aiUF35Q6viWQSEsk/1T3fpuwRp9r8MWPLJZRlLjZecl4OmYcC3a1IzMn4oEN1gJxRJaZCckizyr7m9Mkm493f0pB9M6Pa7QDz3D5+YCy0qu3+NsKApSgEobc2HQnXtn1GE3/zFrjLxKTsWnSFuTEuLGrSsVWoBs5b4EKTJHnBSRcpL3a/A7++CVG/zxVHt8QSjQ/Cb4GQZx/jyQHJZCP7uqnge2DBKB2/QuKMmcl8sF
x-amz-target:AmazonSSM.ListDocuments
content-type;host;x-amz-date;x-amz-security-token;x-amz-target
769c5616cb57fca6e74861906824d48410e9a1c6052187a8c2afaeda27fb55b6
[DEBUG] 2017-07-12T07:22:50.76Z e8984d42-66d2-11e7-a7af-510b0421530a StringToSign:
AWS4-HMAC-SHA256
20170712T072250Z
20170712/us-east-1/ssm/aws4_request
78f369959524afc6a18bbaba60b947d6c02a25f147319e2cbbf673cb7ab4b987
[DEBUG] 2017-07-12T07:22:50.77Z e8984d42-66d2-11e7-a7af-510b0421530a Signature:
dabe509b02c447b3d3612fc0837ba6ccc14c0fafa6e4be6518328e97a3b83840
[DEBUG] 2017-07-12T07:22:50.100Z e8984d42-66d2-11e7-a7af-510b0421530a Sending http request: <PreparedRequest [POST]>
[INFO] 2017-07-12T07:22:50.100Z e8984d42-66d2-11e7-a7af-510b0421530a Starting new HTTPS connection (1): ssm.us-east-1.amazonaws.com
[DEBUG] 2017-07-12T07:22:50.303Z e8984d42-66d2-11e7-a7af-510b0421530a "POST / HTTP/1.1" 200 167
[DEBUG] 2017-07-12T07:22:50.304Z e8984d42-66d2-11e7-a7af-510b0421530a Response headers: {'x-amzn-requestid': 'e961de9e-66d2-11e7-bf0c-c5a737f98d7b', 'date': 'Wed, 12 Jul 2017 07:22:49 GMT', 'content-length': '167', 'content-type': 'application/x-amz-json-1.1'}
[DEBUG] 2017-07-12T07:22:50.316Z e8984d42-66d2-11e7-a7af-510b0421530a Response body:
{
"DocumentIdentifiers": [
{
"DocumentType": "Command",
"DocumentVersion": "1",
"Name": "ASGLogBackup",
"Owner": "350785128185",
"PlatformTypes": [
"Linux"
],
"SchemaVersion": "1.2"
}
]
}
[DEBUG] 2017-07-12T07:22:50.317Z e8984d42-66d2-11e7-a7af-510b0421530a Event needs-retry.ssm.ListDocuments: calling handler <botocore.retryhandler.RetryHandler object at 0x7faf2de0f150>
[DEBUG] 2017-07-12T07:22:50.317Z e8984d42-66d2-11e7-a7af-510b0421530a No retry needed.
[INFO] 2017-07-12T07:22:50.317Z e8984d42-66d2-11e7-a7af-510b0421530a Documents list: {u'DocumentIdentifiers': [{u'Name': u'ASGLogBackup', u'PlatformTypes': [u'Linux'], u'DocumentVersion': u'1', u'DocumentType': u'Command', u'Owner': u'350785128185', u'SchemaVersion': u'1.2'}], 'ResponseMetadata': {'RetryAttempts': 0, 'HTTPStatusCode': 200, 'RequestId': 'e961de9e-66d2-11e7-bf0c-c5a737f98d7b', 'HTTPHeaders': {'x-amzn-requestid': 'e961de9e-66d2-11e7-bf0c-c5a737f98d7b', 'date': 'Wed, 12 Jul 2017 07:22:49 GMT', 'content-length': '167', 'content-type': 'application/x-amz-json-1.1'}}}
[INFO] 2017-07-12T07:22:50.317Z e8984d42-66d2-11e7-a7af-510b0421530a Documents exists: {u'DocumentIdentifiers': [{u'Name': u'ASGLogBackup', u'PlatformTypes': [u'Linux'], u'DocumentVersion': u'1', u'DocumentType': u'Command', u'Owner': u'350785128185', u'SchemaVersion': u'1.2'}], 'ResponseMetadata': {'RetryAttempts': 0, 'HTTPStatusCode': 200, 'RequestId': 'e961de9e-66d2-11e7-bf0c-c5a737f98d7b', 'HTTPHeaders': {'x-amzn-requestid': 'e961de9e-66d2-11e7-bf0c-c5a737f98d7b', 'date': 'Wed, 12 Jul 2017 07:22:49 GMT', 'content-length': '167', 'content-type': 'application/x-amz-json-1.1'}}}
[DEBUG] 2017-07-12T07:22:50.318Z e8984d42-66d2-11e7-a7af-510b0421530a Event before-parameter-build.ssm.ListDocuments: calling handler <function generate_idempotent_uuid at 0x7faf2e0e4d70>
[DEBUG] 2017-07-12T07:22:50.318Z e8984d42-66d2-11e7-a7af-510b0421530a Making request for OperationModel(name=ListDocuments) (verify_ssl=True) with params: {'body': '{"DocumentFilterList": [{"key": "Name", "value": "ASGLogBackup"}]}', 'url': u'https://ssm.us-east-1.amazonaws.com/', 'headers': {'User-Agent': 'Boto3/1.4.4 Python/2.7.12 Linux/4.4.51-40.60.amzn1.x86_64 exec-env/AWS_Lambda_python2.7 Botocore/1.5.52', 'Content-Type': u'application/x-amz-json-1.1', 'X-Amz-Target': u'AmazonSSM.ListDocuments'}, 'context': {'auth_type': None, 'client_region': 'us-east-1', 'has_streaming_input': False, 'client_config': <botocore.config.Config object at 0x7faf2de34390>}, 'query_string': '', 'url_path': '/', 'method': u'POST'}
[DEBUG] 2017-07-12T07:22:50.336Z e8984d42-66d2-11e7-a7af-510b0421530a Event request-created.ssm.ListDocuments: calling handler <bound method RequestSigner.handler of <botocore.signers.RequestSigner object at 0x7faf2de34290>>
[DEBUG] 2017-07-12T07:22:50.336Z e8984d42-66d2-11e7-a7af-510b0421530a Event choose-signer.ssm.ListDocuments: calling handler <function set_operation_specific_signer at 0x7faf2e0e4c80>
[DEBUG] 2017-07-12T07:22:50.337Z e8984d42-66d2-11e7-a7af-510b0421530a Calculating signature using v4 auth.
[DEBUG] 2017-07-12T07:22:50.337Z e8984d42-66d2-11e7-a7af-510b0421530a CanonicalRequest:
POST
/
content-type:application/x-amz-json-1.1
host:ssm.us-east-1.amazonaws.com
x-amz-date:20170712T072250Z
x-amz-security-token:FQoDYXdzELn//////////wEaDHM/oDkHT6rjH9WwOSLmAeFeEyc0+90TM2MhGBO5LPWOa1/fhPFpanPE0aLyIOsVnuvk8EbiGObL/t2zL8YMeVWJNsNB4F1StC9Z7aiUF35Q6viWQSEsk/1T3fpuwRp9r8MWPLJZRlLjZecl4OmYcC3a1IzMn4oEN1gJxRJaZCckizyr7m9Mkm493f0pB9M6Pa7QDz3D5+YCy0qu3+NsKApSgEobc2HQnXtn1GE3/zFrjLxKTsWnSFuTEuLGrSsVWoBs5b4EKTJHnBSRcpL3a/A7++CVG/zxVHt8QSjQ/Cb4GQZx/jyQHJZCP7uqnge2DBKB2/QuKMmcl8sF
x-amz-target:AmazonSSM.ListDocuments
content-type;host;x-amz-date;x-amz-security-token;x-amz-target
769c5616cb57fca6e74861906824d48410e9a1c6052187a8c2afaeda27fb55b6
[DEBUG] 2017-07-12T07:22:50.337Z e8984d42-66d2-11e7-a7af-510b0421530a StringToSign:
AWS4-HMAC-SHA256
20170712T072250Z
20170712/us-east-1/ssm/aws4_request
78f369959524afc6a18bbaba60b947d6c02a25f147319e2cbbf673cb7ab4b987
[DEBUG] 2017-07-12T07:22:50.337Z e8984d42-66d2-11e7-a7af-510b0421530a Signature:
dabe509b02c447b3d3612fc0837ba6ccc14c0fafa6e4be6518328e97a3b83840
[DEBUG] 2017-07-12T07:22:50.337Z e8984d42-66d2-11e7-a7af-510b0421530a Sending http request: <PreparedRequest [POST]>
[DEBUG] 2017-07-12T07:22:50.357Z e8984d42-66d2-11e7-a7af-510b0421530a "POST / HTTP/1.1" 200 167
[DEBUG] 2017-07-12T07:22:50.357Z e8984d42-66d2-11e7-a7af-510b0421530a Response headers: {'x-amzn-requestid': 'e96e3ab5-66d2-11e7-bf0c-c5a737f98d7b', 'date': 'Wed, 12 Jul 2017 07:22:49 GMT', 'content-length': '167', 'content-type': 'application/x-amz-json-1.1'}
[DEBUG] 2017-07-12T07:22:50.357Z e8984d42-66d2-11e7-a7af-510b0421530a Response body:
{
"DocumentIdentifiers": [
{
"DocumentType": "Command",
"DocumentVersion": "1",
"Name": "ASGLogBackup",
"Owner": "350785128185",
"PlatformTypes": [
"Linux"
],
"SchemaVersion": "1.2"
}
]
}
[DEBUG] 2017-07-12T07:22:50.358Z e8984d42-66d2-11e7-a7af-510b0421530a Event needs-retry.ssm.ListDocuments: calling handler <botocore.retryhandler.RetryHandler object at 0x7faf2de0f150>
[DEBUG] 2017-07-12T07:22:50.358Z e8984d42-66d2-11e7-a7af-510b0421530a No retry needed.
[DEBUG] 2017-07-12T07:22:50.358Z e8984d42-66d2-11e7-a7af-510b0421530a Event before-parameter-build.ssm.SendCommand: calling handler <function generate_idempotent_uuid at 0x7faf2e0e4d70>
[DEBUG] 2017-07-12T07:22:50.359Z e8984d42-66d2-11e7-a7af-510b0421530a Making request for OperationModel(name=SendCommand) (verify_ssl=True) with params: {'body': '{"DocumentName": "ASGLogBackup", "InstanceIds": ["i-057beff453ba8887e"], "TimeoutSeconds": 120}', 'url': u'https://ssm.us-east-1.amazonaws.com/', 'headers': {'User-Agent': 'Boto3/1.4.4 Python/2.7.12 Linux/4.4.51-40.60.amzn1.x86_64 exec-env/AWS_Lambda_python2.7 Botocore/1.5.52', 'Content-Type': u'application/x-amz-json-1.1', 'X-Amz-Target': u'AmazonSSM.SendCommand'}, 'context': {'auth_type': None, 'client_region': 'us-east-1', 'has_streaming_input': False, 'client_config': <botocore.config.Config object at 0x7faf2de34390>}, 'query_string': '', 'url_path': '/', 'method': u'POST'}
[DEBUG] 2017-07-12T07:22:50.376Z e8984d42-66d2-11e7-a7af-510b0421530a Event request-created.ssm.SendCommand: calling handler <bound method RequestSigner.handler of <botocore.signers.RequestSigner object at 0x7faf2de34290>>
[DEBUG] 2017-07-12T07:22:50.376Z e8984d42-66d2-11e7-a7af-510b0421530a Event choose-signer.ssm.SendCommand: calling handler <function set_operation_specific_signer at 0x7faf2e0e4c80>
[DEBUG] 2017-07-12T07:22:50.377Z e8984d42-66d2-11e7-a7af-510b0421530a Calculating signature using v4 auth.
[DEBUG] 2017-07-12T07:22:50.377Z e8984d42-66d2-11e7-a7af-510b0421530a CanonicalRequest:
POST
/
content-type:application/x-amz-json-1.1
host:ssm.us-east-1.amazonaws.com
x-amz-date:20170712T072250Z
x-amz-security-token:FQoDYXdzELn//////////wEaDHM/oDkHT6rjH9WwOSLmAeFeEyc0+90TM2MhGBO5LPWOa1/fhPFpanPE0aLyIOsVnuvk8EbiGObL/t2zL8YMeVWJNsNB4F1StC9Z7aiUF35Q6viWQSEsk/1T3fpuwRp9r8MWPLJZRlLjZecl4OmYcC3a1IzMn4oEN1gJxRJaZCckizyr7m9Mkm493f0pB9M6Pa7QDz3D5+YCy0qu3+NsKApSgEobc2HQnXtn1GE3/zFrjLxKTsWnSFuTEuLGrSsVWoBs5b4EKTJHnBSRcpL3a/A7++CVG/zxVHt8QSjQ/Cb4GQZx/jyQHJZCP7uqnge2DBKB2/QuKMmcl8sF
x-amz-target:AmazonSSM.SendCommand
content-type;host;x-amz-date;x-amz-security-token;x-amz-target
f2237f6810448b76d44e17fd66b83b1b4371df545e6117e7f66eebb311631f28
[DEBUG] 2017-07-12T07:22:50.377Z e8984d42-66d2-11e7-a7af-510b0421530a StringToSign:
AWS4-HMAC-SHA256
20170712T072250Z
20170712/us-east-1/ssm/aws4_request
17b7fd589cca1a6a1548ff529c6ec0884756f72920c6cf5d79e9cf8b0d55c76b
[DEBUG] 2017-07-12T07:22:50.377Z e8984d42-66d2-11e7-a7af-510b0421530a Signature:
1cf64492c0ebe9ddcd021fa19fbcf5caeffe46284e55f8b853242c8b1ae8c9a1
[DEBUG] 2017-07-12T07:22:50.377Z e8984d42-66d2-11e7-a7af-510b0421530a Sending http request: <PreparedRequest [POST]>
[DEBUG] 2017-07-12T07:22:50.543Z e8984d42-66d2-11e7-a7af-510b0421530a "POST / HTTP/1.1" 200 528
[DEBUG] 2017-07-12T07:22:50.557Z e8984d42-66d2-11e7-a7af-510b0421530a Response headers: {'x-amzn-requestid': 'e9745538-66d2-11e7-bf0c-c5a737f98d7b', 'date': 'Wed, 12 Jul 2017 07:22:49 GMT', 'content-length': '528', 'content-type': 'application/x-amz-json-1.1'}
[DEBUG] 2017-07-12T07:22:50.557Z e8984d42-66d2-11e7-a7af-510b0421530a Response body:
{
"Command": {
"CommandId": "0ece375e-a643-4474-9642-81185bd7ff4a",
"Comment": "",
"CompletedCount": 0,
"DocumentName": "ASGLogBackup",
"ErrorCount": 0,
"ExpiresAfter": 1499847890.54,
"InstanceIds": [
"i-057beff453ba8887e"
],
"MaxConcurrency": "50",
"MaxErrors": "0",
"NotificationConfig": {
"NotificationArn": "",
"NotificationEvents": [],
"NotificationType": ""
},
"OutputS3BucketName": "",
"OutputS3KeyPrefix": "",
"Parameters": {},
"RequestedDateTime": 1499844170.54,
"ServiceRole": "",
"Status": "Pending",
"StatusDetails": "Pending",
"TargetCount": 1,
"Targets": []
}
}
[DEBUG] 2017-07-12T07:22:50.558Z e8984d42-66d2-11e7-a7af-510b0421530a Event needs-retry.ssm.SendCommand: calling handler <botocore.retryhandler.RetryHandler object at 0x7faf2de0f150>
[DEBUG] 2017-07-12T07:22:50.576Z e8984d42-66d2-11e7-a7af-510b0421530a No retry needed.
[INFO] 2017-07-12T07:22:50.576Z e8984d42-66d2-11e7-a7af-510b0421530a Command sent: {u'Command': {u'Comment': u'', u'Status': u'Pending', u'MaxErrors': u'0', u'Parameters': {}, u'ExpiresAfter': datetime.datetime(2017, 7, 12, 8, 24, 50, 540000, tzinfo=tzlocal()), u'ServiceRole': u'', u'DocumentName': u'ASGLogBackup', u'TargetCount': 1, u'OutputS3BucketName': u'', u'NotificationConfig': {u'NotificationArn': u'', u'NotificationEvents': [], u'NotificationType': u''}, u'CompletedCount': 0, u'Targets': [], u'StatusDetails': u'Pending', u'ErrorCount': 0, u'OutputS3KeyPrefix': u'', u'RequestedDateTime': datetime.datetime(2017, 7, 12, 7, 22, 50, 540000, tzinfo=tzlocal()), u'CommandId': u'0ece375e-a643-4474-9642-81185bd7ff4a', u'InstanceIds': [u'i-057beff453ba8887e'], u'MaxConcurrency': u'50'}, 'ResponseMetadata': {'RetryAttempts': 0, 'HTTPStatusCode': 200, 'RequestId': 'e9745538-66d2-11e7-bf0c-c5a737f98d7b', 'HTTPHeaders': {'x-amzn-requestid': 'e9745538-66d2-11e7-bf0c-c5a737f98d7b', 'date': 'Wed, 12 Jul 2017 07:22:49 GMT', 'content-length': '528', 'content-type': 'application/x-amz-json-1.1'}}}
[DEBUG] 2017-07-12T07:22:50.577Z e8984d42-66d2-11e7-a7af-510b0421530a Event before-parameter-build.ssm.ListCommandInvocations: calling handler <function generate_idempotent_uuid at 0x7faf2e0e4d70>
[DEBUG] 2017-07-12T07:22:50.577Z e8984d42-66d2-11e7-a7af-510b0421530a Making request for OperationModel(name=ListCommandInvocations) (verify_ssl=True) with params: {'body': '{"InstanceId": "i-057beff453ba8887e", "CommandId": "0ece375e-a643-4474-9642-81185bd7ff4a", "Details": false}', 'url': u'https://ssm.us-east-1.amazonaws.com/', 'headers': {'User-Agent': 'Boto3/1.4.4 Python/2.7.12 Linux/4.4.51-40.60.amzn1.x86_64 exec-env/AWS_Lambda_python2.7 Botocore/1.5.52', 'Content-Type': u'application/x-amz-json-1.1', 'X-Amz-Target': u'AmazonSSM.ListCommandInvocations'}, 'context': {'auth_type': None, 'client_region': 'us-east-1', 'has_streaming_input': False, 'client_config': <botocore.config.Config object at 0x7faf2de34390>}, 'query_string': '', 'url_path': '/', 'method': u'POST'}
[DEBUG] 2017-07-12T07:22:50.596Z e8984d42-66d2-11e7-a7af-510b0421530a Event request-created.ssm.ListCommandInvocations: calling handler <bound method RequestSigner.handler of <botocore.signers.RequestSigner object at 0x7faf2de34290>>
[DEBUG] 2017-07-12T07:22:50.597Z e8984d42-66d2-11e7-a7af-510b0421530a Event choose-signer.ssm.ListCommandInvocations: calling handler <function set_operation_specific_signer at 0x7faf2e0e4c80>
[DEBUG] 2017-07-12T07:22:50.597Z e8984d42-66d2-11e7-a7af-510b0421530a Calculating signature using v4 auth.
[DEBUG] 2017-07-12T07:22:50.597Z e8984d42-66d2-11e7-a7af-510b0421530a CanonicalRequest:
POST
/
content-type:application/x-amz-json-1.1
host:ssm.us-east-1.amazonaws.com
x-amz-date:20170712T072250Z
x-amz-security-token:FQoDYXdzELn//////////wEaDHM/oDkHT6rjH9WwOSLmAeFeEyc0+90TM2MhGBO5LPWOa1/fhPFpanPE0aLyIOsVnuvk8EbiGObL/t2zL8YMeVWJNsNB4F1StC9Z7aiUF35Q6viWQSEsk/1T3fpuwRp9r8MWPLJZRlLjZecl4OmYcC3a1IzMn4oEN1gJxRJaZCckizyr7m9Mkm493f0pB9M6Pa7QDz3D5+YCy0qu3+NsKApSgEobc2HQnXtn1GE3/zFrjLxKTsWnSFuTEuLGrSsVWoBs5b4EKTJHnBSRcpL3a/A7++CVG/zxVHt8QSjQ/Cb4GQZx/jyQHJZCP7uqnge2DBKB2/QuKMmcl8sF
x-amz-target:AmazonSSM.ListCommandInvocations
content-type;host;x-amz-date;x-amz-security-token;x-amz-target
06321604afedcd5513b2df3a174aad8faf73c23978da2c8fa03ff26689ddbaa0
[DEBUG] 2017-07-12T07:22:50.597Z e8984d42-66d2-11e7-a7af-510b0421530a StringToSign:
AWS4-HMAC-SHA256
20170712T072250Z
20170712/us-east-1/ssm/aws4_request
aeddc98a9eb7a4eaec8aa55d7eefe079d6f56c45766155b52abf22bdc4818c38
[DEBUG] 2017-07-12T07:22:50.597Z e8984d42-66d2-11e7-a7af-510b0421530a Signature:
e5fc7fac6dae183c6697431e16d769d2be5555680f04742f4f2783c8ec5abe7c
[DEBUG] 2017-07-12T07:22:50.598Z e8984d42-66d2-11e7-a7af-510b0421530a Sending http request: <PreparedRequest [POST]>
[DEBUG] 2017-07-12T07:22:50.631Z e8984d42-66d2-11e7-a7af-510b0421530a "POST / HTTP/1.1" 200 25
[DEBUG] 2017-07-12T07:22:50.631Z e8984d42-66d2-11e7-a7af-510b0421530a Response headers: {'x-amzn-requestid': 'e995e711-66d2-11e7-bf0c-c5a737f98d7b', 'date': 'Wed, 12 Jul 2017 07:22:49 GMT', 'content-length': '25', 'content-type': 'application/x-amz-json-1.1'}
[DEBUG] 2017-07-12T07:22:50.631Z e8984d42-66d2-11e7-a7af-510b0421530a Response body:
{
"CommandInvocations": []
}
[DEBUG] 2017-07-12T07:22:50.632Z e8984d42-66d2-11e7-a7af-510b0421530a Event needs-retry.ssm.ListCommandInvocations: calling handler <botocore.retryhandler.RetryHandler object at 0x7faf2de0f150>
[DEBUG] 2017-07-12T07:22:50.632Z e8984d42-66d2-11e7-a7af-510b0421530a No retry needed.
[ERROR] 2017-07-12T07:22:50.632Z e8984d42-66d2-11e7-a7af-510b0421530a Error: list index out of range
END RequestId: e8984d42-66d2-11e7-a7af-510b0421530a
REPORT RequestId: e8984d42-66d2-11e7-a7af-510b0421530a Duration: 561.05 ms Billed Duration: 600 ms Memory Size: 128 MB Max Memory Used: 40 MB
I couldn't find any more details to troubleshoot...
Thanks for the script, solves a good problem.
Everything looks good until https://github.com/aws-samples/aws-lambda-lifecycle-hooks-function/blob/master/cloudformation/lambda_backup.py#L61
An error occurred (InvalidInstanceId) when calling the SendCommand operation:
I tried to manually execute the aws ssm send-command --instance-ids "i-0657394a515364bd0" --document-name "ASGLogBackup1" --timeout "120" --region us-east-1
from the new instance on the instance which is in terminate:wait
state and got the same response.
SSM document; Step 5.
Seems that the line where the SNSTARGET is set, uses the REGION variable what will be set few lines later, result is that the notification doesn't arrive.
Regarding the whole procedure, am I supposed to set any particular set of permissions on the bucket?
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='<your_bucket_name>'",
"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}':<your_account_id>:<your_sns_ backupoutcome_topic>'",
"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}"
]
}
]
}
}
}
----------ERROR-------
% 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 19 100 19 0 0 19 0 0:00:01 --:--:-- 0:00:01 6333
% 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 10 100 10 0 0 10 0 0:00:01 --:--:-- 0:00:01 3333
/var/lib/amazon/ssm/i-00fb53e077def7958/document/orchestration/d4f624b8-7c6d-44b6-a6dd-a88c345c4424/awsrunShellScript/0.awsrunShellScript/_script.sh: line 22: unexpected EOF while looking for matching `''
/var/lib/amazon/ssm/i-00fb53e077def7958/document/orchestration/d4f624b8-7c6d-44b6-a6dd-a88c345c4424/awsrunShellScript/0.awsrunShellScript/_script.sh: line 24: syntax error: unexpected end of file
failed to run commands: exit status 2
The script got executed successfully, sharing the output from RUN Command console below.
{
"MessageId": "2fe8d6c4-9159-5ab0-adb1-82ccb3f575dd"
}
----------ERROR-------
% 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 19 100 19 0 0 19 0 0:00:01 --:--:-- 0:00:01 6333
% 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 11 100 11 0 0 11 0 0:00:01 --:--:-- 0:00:01 3666
The SNS notification received successfully at the said email, content of the email below, which shows the tar file being uploaded to the said S3 Bucket as well.
Completed 256.0 KiB/8.6 MiB (310.9 KiB/s) with 1 file(s) remaining
Completed 512.0 KiB/8.6 MiB (611.7 KiB/s) with 1 file(s) remaining
Completed 588.0 KiB/8.6 MiB (682.9 KiB/s) with 1 file(s) remaining
Completed 844.0 KiB/8.6 MiB (961.5 KiB/s) with 1 file(s) remaining
Completed 1.1 MiB/8.6 MiB (1.2 MiB/s) with 1 file(s) remaining
Completed 1.3 MiB/8.6 MiB (1.5 MiB/s) with 1 file(s) remaining
Completed 1.6 MiB/8.6 MiB (1.7 MiB/s) with 1 file(s) remaining
Completed 1.8 MiB/8.6 MiB (2.0 MiB/s) with 1 file(s) remaining
Completed 2.1 MiB/8.6 MiB (2.3 MiB/s) with 1 file(s) remaining
Completed 2.3 MiB/8.6 MiB (2.5 MiB/s) with 1 file(s) remaining
Completed 2.6 MiB/8.6 MiB (2.8 MiB/s) with 1 file(s) remaining
Completed 2.8 MiB/8.6 MiB (3.0 MiB/s) with 1 file(s) remaining
Completed 3.1 MiB/8.6 MiB (3.3 MiB/s) with 1 file(s) remaining
Completed 3.3 MiB/8.6 MiB (3.6 MiB/s) with 1 file(s) remaining
Completed 3.6 MiB/8.6 MiB (3.8 MiB/s) with 1 file(s) remaining
Completed 3.8 MiB/8.6 MiB (4.1 MiB/s) with 1 file(s) remaining
Completed 4.1 MiB/8.6 MiB (4.3 MiB/s) with 1 file(s) remaining
Completed 4.3 MiB/8.6 MiB (4.6 MiB/s) with 1 file(s) remaining
Completed 4.6 MiB/8.6 MiB (4.8 MiB/s) with 1 file(s) remaining
Completed 4.8 MiB/8.6 MiB (5.1 MiB/s) with 1 file(s) remaining
Completed 5.1 MiB/8.6 MiB (5.3 MiB/s) with 1 file(s) remaining
Completed 5.3 MiB/8.6 MiB (5.6 MiB/s) with 1 file(s) remaining
Completed 5.6 MiB/8.6 MiB (5.8 MiB/s) with 1 file(s) remaining
Completed 5.8 MiB/8.6 MiB (6.1 MiB/s) with 1 file(s) remaining
Completed 6.1 MiB/8.6 MiB (6.3 MiB/s) with 1 file(s) remaining
Completed 6.3 MiB/8.6 MiB (6.6 MiB/s) with 1 file(s) remaining
Completed 6.6 MiB/8.6 MiB (6.8 MiB/s) with 1 file(s) remaining
Completed 6.8 MiB/8.6 MiB (7.0 MiB/s) with 1 file(s) remaining
Completed 7.1 MiB/8.6 MiB (7.1 MiB/s) with 1 file(s) remaining
Completed 7.3 MiB/8.6 MiB (7.4 MiB/s) with 1 file(s) remaining
Completed 7.6 MiB/8.6 MiB (7.6 MiB/s) with 1 file(s) remaining
Completed 7.8 MiB/8.6 MiB (7.8 MiB/s) with 1 file(s) remaining
Completed 8.1 MiB/8.6 MiB (8.0 MiB/s) with 1 file(s) remaining
Completed 8.3 MiB/8.6 MiB (8.2 MiB/s) with 1 file(s) remaining
Completed 8.6 MiB/8.6 MiB (8.5 MiB/s) with 1 file(s) remaining
upload: ../../tmp/i-026c89dab699e346b.tar to s3://asgami-backup/i-026c89dab699e346b/i-026c89dab699e346b.tar
Sharing the screenshot of the S3 bucket for your reference as no files got uploaded in the bucket.
Hello,
Thank you for your job.
The lambda raised an error :
Error: name 'parsed_message' is not defined
I didn't find where this var is defined.
Thank you for your support.
Damien.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.