The String macro does not strip from Right correctly.
Closed this issue · 2 comments
edenhare commented
There is a bug in the String macro Lambda function when using StripFrom Right.
In this code block
elif operation == "MaxLength":
length = int(event["params"]["Length"])
if len(input) <= length:
response["fragment"] = input
elif "StripFrom" in event["params"]:
if event["params"]["StripFrom"] == "Left":
response["fragment"] = input[len(input)-length:]
elif event["params"]["StripFrom"] != "Right":
response["status"] = "failure"
else:
response["fragment"] = input[:length]
the else
is never executed when StripFrom is present to return the result. The transform lambda successfully executes, but since there is no response['fragment'] is the return to CloudFormation, a template processing error results.
If the code is changed to
elif operation == "MaxLength":
length = int(event["params"]["Length"])
if len(input) <= length:
response["fragment"] = input
elif "StripFrom" in event["params"]:
if event["params"]["StripFrom"] == "Left":
response["fragment"] = input[len(input)-length:]
elif event["params"]["StripFrom"] != "Right":
response["status"] = "failure"
else:
response["fragment"] = input[:length]
the the macros return correctly when using StripFrom Right and the response['fragment'] is in the return back to CloudFormation.
ericzbeard commented
We are archiving this repository in favor of similar content located here: https://github.com/aws-cloudformation/aws-cloudformation-templates/tree/main/aws/services/CloudFormation/MacrosExamples