Home:ALL Converter>Parsing Json - from sql (Aurora) to aws lambda

Parsing Json - from sql (Aurora) to aws lambda

Ask Time:2018-04-05T18:57:30         Author:Barath Ravichander

Json Formatter

i am not able to parse a json as is from sql to lambda. Lets say below is my stored procedure that calls lambda api.

CALL mysql.lambda_async('arn:aws:lambda:us-east-1:<account_id>:function:<sample_name>',  <---- this should be your lambda function ARN
     CONCAT('{ "message_id" : "', 'test.txt', 
            '", "transaction_json" : "', '{"glossary": {
                                                "title": "example glossary",
                                                    "GlossDiv": {
                                                        "title": "S",
                                                        "GlossList": {
                                                            "GlossEntry": {
                                                                "ID": "SGML",
                                                                "SortAs": "SGML",
                                                                "GlossTerm": "Standard Generalized Markup Language",
                                                                "Acronym": "SGML",
                                                                "Abbrev": "ISO 8879:1986",
                                                                "GlossDef": {
                                                                    "para": "A meta-markup language, used to create markup languages such as DocBook.",
                                                                    "GlossSeeAlso": ["GML", "XML"]
                                                                "GlossSee": "markup"
                '", "s3_bucket" : "', 'br-gtosbx-gtps-data-useast-1-s3',

Now this will call a lambda function which is written in python 3.6

def s3_publish_message(event, context):
    import boto3
    import botocore
    import json

    s3 = boto3.client('s3')

    s3_bucket = event['s3_bucket']
    #transaction_json = event['transaction_json']
        event_str = str(json.dumps(event['transaction_json'])).encode("utf-8")
        print("s3 Load Completed")
    except Exception as err:
        print("Could not convert event to string for storage. Threw exception: {}".format(err))

    message_id = event['message_id']


when i run the stored procedure in mysql i get below error.

Error Code: 1873. Lambda API returned error: Invalid Request Content. Could not parse request body into json: Unexpected character ('g' (code 103)): was expecting comma to separate Object entries  at [Source: [B@616b0a0f; line: 1, column: 55]

is there any way i can handle this or should we send json without (")

Author:Barath Ravichander,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/49670679/parsing-json-from-sql-aurora-to-aws-lambda