aws-samples / automatic-EBS-failed-snashot-recovery

MIT No Attribution
1 stars 0 forks source link

Error Running Test on 'Successful' Snapshot #1

Open MuskratAggie opened 3 weeks ago

MuskratAggie commented 3 weeks ago

This setup and these instructions are great! Thanks!

I went through all of the instructions a couple times, but I'm getting an error when the Lambda tries to run: Exception argument of type 'NoneType' is not iterable ... [ERROR] UnboundLocalError: cannot access local variable 'VolumeId' where it is not associated with a value Traceback (most recent call last): File "/var/task/lambda_function.py", line 34, in lambda_handler process_message(message) File "/var/task/lambda_function.py", line 90, in process_message batch_item_failures.append({"itemIdentifier": message['messageId'], "VolumeID": VolumeId, "Region": body['region']})

Any thoughts on why its having issues pulling the VolumeId? I tried adding "DescribeVolumeAttribute" to the EC2 permissions, but received the same error.

trinacriax commented 2 weeks ago

Hi, sorry for the delay. Here the question is why there is an Exception? This is not related to IAM permissions, indeed, it is a problem in the lambda function input. Are you running a test with a JSON or you created the snapshot from volume to trigger the EventBridge rule till the lambda? Please post the full log: the actual issue is not related to volumeID, but why there is an exception. I deployed everything from scratch, following the instructions. Then I created a snapshot from a volume with source_tag_Key="EBS-Snapshot" and source_tag_Value="LambdaRecovery" and I did not experience this issue.

MuskratAggie commented 2 weeks ago

I triggered the Eventbridge from a Successful snapshot. I'm going to delete everything I created and try again. I will update you when I've completed that. Thanks for the response!

MuskratAggie commented 2 weeks ago

Deleted everything from the previous attempt and started from scratch. Got the same error when the Lambda function is triggered. So it looks like everything is triggering correctly, just when the Python script runs, we get this error...here's the full error:

START RequestId: 4b078ef6-d7ad-5139-8d68-d16b35c40007 Version: $LATEST
BEFORE - Source Tag  {'Key': 'xx-xxx-EBS-Recovery', 'Value': 'xxx-LambdaSnapshotRecovery'}
Exception  argument of type 'NoneType' is not iterable
LAMBDA_WARNING: Unhandled exception. The most likely cause is an issue in the function code. However, in rare cases, a Lambda runtime update can cause unexpected function behavior. For functions using managed runtimes, runtime updates can be triggered by a function change, or can be applied automatically. To determine if the runtime has been updated, check the runtime version in the INIT_START log entry. If this error correlates with a change in the runtime version, you may be able to mitigate this error by temporarily rolling back to the previous runtime version. For more information, see https://docs.aws.amazon.com/lambda/latest/dg/runtimes-update.html
[ERROR] UnboundLocalError: cannot access local variable 'VolumeId' where it is not associated with a value
Traceback (most recent call last):
  File "/var/task/lambda_function.py", line 34, in lambda_handler
    process_message(message)
  File "/var/task/lambda_function.py", line 90, in process_message
    batch_item_failures.append({"itemIdentifier": message['messageId'], "VolumeID": VolumeId, "Region": body['region']})
END RequestId: 4b078ef6-d7ad-5139-8d68-d16b35c40007
REPORT RequestId: 4b078ef6-d7ad-5139-8d68-d16b35c40007  Duration: 953.94 ms Billed Duration: 954 ms Memory Size: 128 MB Max Memory Used: 90 MB  

Thanks again for the response, and any thoughts on what might be going on.

trinacriax commented 2 weeks ago

The actual issue is the "None Type" which leads to the exception. I suggest in the lambda to print the event and the message, so you have it in the log stream, to intercept this "None Type".