Home > Software engineering >  lambda aws syntax error : missing ) after argument list
lambda aws syntax error : missing ) after argument list

Time:11-22

const AWS = require('aws-sdk');
const ddb = new AWS.DynamoDB.DocumentClient({region: 'ap-southeast-1'})

exports.handler = async(event) => {
    //TODO implement
    var obj = JSON.parse(JSON.stringify(event.queryStringParameters));
    const requestId = context.awsRequestId;
    await createMessage(requestId).then(() => {
        callback(null, {
        statusCode: 200, 
        body:  `
            <hl>query string parameters</hl>
            <p>${JSON.stringify(event.queryStringParameters)}</p>
            <p>one: ${obj.one}</p>
            <hr/>
            <hl>path</hl>
            <p>${JSON.stringify(event.requestContext.http.path)}</p>
            <hr/>
         `, 
       header: {
            'Content-Type' :  'text/html; charset=uft-8',
        },
    }
function createMessage(requestId) {
     const params = {
        TableName: 'Message',
        Item: {
            'Hello' : 'one'
        }
     }
    return ddb.put(params).promise();
}; 
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

CodePudding user response:

These lines:

    await createMessage(requestId).then(() => {
        callback(null, {

open two sets of parentheses ( that are not closed.

I highly recommend using a text editor (eg Visual Studio Code) that highlights parentheses to help identify these issues.

CodePudding user response:

thanks there's no problem about bracket now!. but i get new error 'Unexpected token u in JSON at position 0'

const AWS = require('aws-sdk');
const ddb = new AWS.DynamoDB.DocumentClient({region: 'ap-southeast-1'});

exports.handler = async (event, context, callback) => {
    var obj = JSON.parse(JSON.stringify(event.queryStringParameters));
    const requestId = context.awsRequestId;
    await createMessage(requestId).then(() => {
        callback(null, {
            statusCode: 200,
            body: `
            <hl>query string parameters</hl>
            <p>${JSON.stringify(event.queryStringParameters)}</p>
            <p>one: ${obj.one}</p>
            <hr/>
            <hl>path</hl>
            <p>${JSON.stringify(event.requestContext.http.path)}</p>
            <hr/>
           `,
            headers: {
                 'Content-Type' :  'text/html; charset=uft-8',
            }
        });
    }).catch((err) => {
        console.error(err)
    })
};

function createMessage(requestId) {
    const params = {
        TableName: 'Message',
        Item: {
            'messageId' : '321',
        }
    }
    return ddb.put(params).promise();
}
<iframe name="sif2" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

  • Related