Calling the invoke API action failed with this message: Unexpected token 'p', ..."feeling": positive, "... is not valid JSON
I get this error message, I don't know exactly how to configure it well, how can I write this code in JSON if elif else
# In a name-value pair you can extract the "value" of the pair using the "name" of the pair.
# Here the id value is extracted from the event Lambda parameter and passed to a variable called feeling.
feeling = event["feeling"]
# Here the message value is extracted from the event Lambda parameter and passed to a variable called message.
message = event["message"]
# The variables are printed here, which means the variable values will be displayed in CloudWatch logs and the Execution Results panel.
print(feeling)
print(positive)
# In Python, you can create a variable with no value using the Built-in constant None. This means the variable "custom_message" currently has no value.
custom_message = None
# In Python, we use the if-elif-else to create a conditional execution. https://docs.python.org/3/reference/compound_stmts.html#the-if-statement
# That is, if the value of feeling is equal to 0, we execute the statement inside its block
if feeling == 0:
# Only execute if id is equal to 1
# The variable custom_message combines "Message for code 0:" string with the variable message
custom_message = "Message for code 0: " + message
elif feeling == 1:
# The variable custom_message combines "Message for code 1:" string with the variable message
custom_message = "Message for code 1: " + message
else:
# The variable custom_message combines "Message for all other codes:" string with the variable message
custom_message = "Message for all other codes: " + message
}
# Optionally, the handler can return a value. What happens to the returned value depends on the invocation type you use when invoking the Lambda function
# In this lab we use synchronous execution, so we need to create a response for the lambda function.
# We created a "response" variable that has a structure of name-value pairs using the id and custom_message created earlier.
response = {
# In this name-value pair, the literal value "message" will store the value of the variable custom_message.
"feeling": I love the park,
# In this name-value pair, the literal value "id" will store the value of the variable id.
"message": Message for all other codes,
}
# Finally, we return the values from response variable to the caller, which could be a test event or an AWS service performing a synchronous call.
# The execution of the lambda function is finished.
return response