I have been struggling with AWS Step Functions for hours now. The use case is quite simple as I want to get gradually familiar with AWS Step Functions. However, I think I do not understand how they handle errors that come back from a failed lambda function.
Here is the corresponding code:
{ "Comment": "A simple AWS Step Functions for managing users with in the context of the AWS Training Initiative at AXA.", "StartAt": "Process-All-Deletion", "States": { "Process-All-Deletion": { "Type": "Map", "InputPath": "$", "ItemsPath": "$.Users", "MaxConcurrency": 0, "Iterator": { "StartAt": "DeleteAccessKeys", "States": { "DeleteAccessKeys": { "Type": "Task", "Resource": "arn:aws:lambda:eu-central-1:###:function:listUserAccessKeys", "Next": "DetachUserPolicy", "Catch": [ { "ErrorEquals": ["NoSuchEntityException"], "ResultPath": "$.DeleteAccessKeysError", "Next": "CatchDeleteAccessKeysError" } ] }, "DetachUserPolicy": { "Type": "Task", "Resource": "arn:aws:lambda:eu-central-1:###:function:detachUserPolicy", "Next": "DeleteIamUser", "Catch": [ { "ErrorEquals": ["States.TaskFailed"], "ResultPath": "$.ErrorDescription", "Next": "CatchDeleteUserPolicyError" } ] }, "DeleteIamUser": { "Type": "Task", "Resource": "arn:aws:lambda:eu-central-1:###:function:deleteIamUser", "End": true, "Catch": [ { "ErrorEquals": ["States.TaskFailed"], "ResultPath": "$.ErrorDescription", "Next": "CatchDeleteIamUserError" } ] }, "CatchDeleteIamUserError": { "Type": "Task", "Resource": "arn:aws:lambda:eu-central-1:###:function:errorHandler", "End": true }, "CatchDeleteAccessKeysError": { "Type": "Task", "Resource": "arn:aws:lambda:eu-central-1:###:function:errorHandler", "Next": "DetachUserPolicy" }, "CatchDeleteUserPolicyError": { "Type": "Task", "Resource": "arn:aws:lambda:eu-central-1:###:function:errorHandler", "Next": "DeleteIamUser" } } }, "ResultPath": "$.Result", "End": true } } } So basically the state machine should catch the error properly and the status should be orange respectively 'caught error' in 'DeleteAccessKeys'. Instead it turns into green.
This is the code of my lambda function:
import boto3 import botocore print('Loading deleteUserAccessKeys function...') def deleteUserAccessKeys(message, context): # Get IAM client client = boto3.client('iam') item = message['Name'] try: # List all keys associated with the user result = client.list_access_keys(UserName=item) accessKeyIds = [accessKeyId for element['AccessKeyId'] in result['AccessKeyMetadata']] # Exit if there are no access keys if not accessKeyIds: return message # Delete all keys associated with the user for element in accessKeyIds: client.delete_access_key( UserName=item, AccessKeyId=element ) message['DeletedAccessKeys']=len(accessKeyIds) print(message) return message except botocore.exceptions.ClientError as error: print(error.response) if error.response['Error']['Code'] == 'NoSuchEntity': print('Entity not found exception') raise error else: raise Exception("Failed! Check the error!") What might be the issue or what did I wrongly configure?


Outputs. Don't know why console shows its as green. Maybe some strange display bug?. More importantly, does your machine works as expected, regardless of what the console shows?