AWS lambda API error required tempate _id, shortid, name



  • I'm seeing the following error when calling an API tied to the jsreports aws function. This works when I call the API directly to the JRS Report console. Any ideas on what I may be doing wrong?

    Fri Aug 11 17:27:59 UTC 2023 : HTTP Method: POST, Resource Path: /v1/report
    Fri Aug 11 17:27:59 UTC 2023 : Method request path: {}
    Fri Aug 11 17:27:59 UTC 2023 : Method request query string: {}
    Fri Aug 11 17:27:59 UTC 2023 : Method request headers: {}
    Fri Aug 11 17:27:59 UTC 2023 : Method request body before transformations: {
    "template":{"name": "SpgmJobSchedule", "shortid":"t2mHjC56p"},
    "folder": {"shortid": "MHhhPe5"},
    "options":{"reports":{"save":true} },
    "data":{
    "header": {
    "params": {
    "applicationGuid": "0B43E124-7755-4194-A441-1836F8E6DB48",
    "jobId": "10024596"
    },
    "otherInfo": {
    "correlationId": "6e157773-be6f-477d-9170-bc169d0de6ea"
    }
    },
    "result": [
    {
    "jobName": "Job 3",
    "subdivisionName": "subDiv 1",
    "taskId": 37,
    "taskName": "task 37",
    "taskStatus": "A",
    "adjStartDate": "2021-10-07T00:00:00.000Z",
    "initStartDate": "2021-10-07T00:00:00.000Z",
    "daysBehind": 0,
    "supplierName": "Self Supplied",
    "phaseGroup": 0
    }[TRUNCATED]
    Fri Aug 11 17:27:59 UTC 2023 : Endpoint request URI: https://lambda.us-west-2.amazonaws.com/2015-03-31/functions/arn:aws:lambda:region:acct:function:SPGMJSReport-function/invocations
    Fri Aug 11 17:27:59 UTC 2023 : Endpoint request headers: {X-Amz-Date=20230811T172759Z, x-amzn-apigateway-api-id=xxxx, Accept=application/json, User-Agent=AmazonAPIGateway_xxxx, Host=lambda.us-west-2.amazonaws.com, X-Amz-Content-Sha256=1ac0742, X-Amzn-Trace-Id=Root=1-64d66f9f-, x-amzn-lambda-integration-tag=6903, Authorization=********, X-Amz-Source-Arn=arn:aws:execute-api:us-west-2:xxxxxx:xxxxi/test-invoke-stage/POST/v1/report, X-Amz-Security-Token=IQoJbvAw2+TF [TRUNCATED]
    Fri Aug 11 17:27:59 UTC 2023 : Endpoint request body after transformations: {"resource":"/v1/report","path":"/v1/report","httpMethod":"POST","headers":null,"multiValueHeaders":null,"queryStringParameters":null,"multiValueQueryStringParameters":null,"pathParameters":null,"stageVariables":null,"requestContext":{"resourceId":"kno7a3","resourcePath":"/v1/report","httpMethod":"POST","extendedRequestId":"JgZg7EzRvHcF9Rg=","requestTime":"11/Aug/2023:17:27:59 +0000","path":"/v1/report","accountId":"xxx1","protocol":"HTTP/1.1","stage":"test-invoke-stage","domainPrefix":"testPrefix","requestTimeEpoch":1691774879233,"requestId":"6903d7ad-f93b-40bc-9768-ea14a9d029ef","identity":{"cognitoIdentityPoolId":null,"cognitoIdentityId":null,"apiKey":"test-invoke-api-key","principalOrgId":null,"cognitoAuthenticationType":null,"userArn":"arn:aws:sts::xxxxx:assumed-role/AWSReservedSSO_AWSAdministratorAccess_xxxx/jrod@xx.com","apiKeyId":"test-invoke-api-key-id","userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) Apple [TRUNCATED]
    Fri Aug 11 17:27:59 UTC 2023 : Sending request to https://lambda.us-west-2.amazonaws.com/2015-03-31/functions/arn:aws:lambda:region:xxxxx:function:SPGMJSReport-function/invocations
    Fri Aug 11 17:27:59 UTC 2023 : Received response. Status: 200, Integration latency: 163 ms
    Fri Aug 11 17:27:59 UTC 2023 : Endpoint response headers: {Date=Fri, 11 Aug 2023 17:27:59 GMT, Content-Type=application/json, Content-Length=1091, Connection=keep-alive, x-amzn-RequestId=2de01b49-3ecb-401c-aede-f34ca5fddbed, X-Amz-Function-Error=Unhandled, x-amzn-Remapped-Content-Length=0, X-Amz-Executed-Version=$LATEST, X-Amzn-Trace-Id=root=1-64d66f9f-7faf64125e31ef2c052242f3;sampled=0;lineage=2b960001:0}
    Fri Aug 11 17:27:59 UTC 2023 : Endpoint response body before transformations: {"errorType":"Error","errorMessage":"Template must contains _id, name, shortid or content attribute","trace":["Error: Template must contains _id, name, shortid or content attribute"," at module.exports (/opt/nodejs/node_modules/@jsreport/jsreport-core/lib/shared/createError.js:10:13)"," at WorkerReporter.createError (/opt/nodejs/node_modules/@jsreport/jsreport-core/lib/shared/reporter.js:47:12)"," at AsyncFunction.<anonymous> (/opt/nodejs/node_modules/@jsreport/jsreport-core/lib/worker/templates.js:14:24)"," at ListenerCollection.fire (/opt/nodejs/node_modules/@jsreport/jsreport-core/lib/shared/listenerCollection.js:157:32)"," at async beforeRender (/opt/nodejs/node_modules/@jsreport/jsreport-core/lib/worker/render/render.js:25:5)"," at async WorkerReporter._render (/opt/nodejs/node_modules/@jsreport/jsreport-core/lib/worker/render/render.js:146:7)"," at async /opt/nodejs/node_modules/@jsreport/jsreport-core/lib/worker/reporter.js:179:19"," [TRUNCATED]
    Fri Aug 11 17:27:59 UTC 2023 : Lambda execution failed with status 200 due to customer function error: Template must contains _id, name, shortid or content attribute. Lambda request id: 2de01b49-3ecb-401c-aede-f34ca5fddbed
    Fri Aug 11 17:27:59 UTC 2023 : Method completed with status: 502



  • Could you share the relevant code in lambda?
    It looks like the object you pass as param to the jsreport.render doesn't include template.name

    Note we have lambda tutorial here
    https://jsreport.net/learn/aws-lambda-serverless



  • It looks like I was missing the "renderRequest" tag around the payload. This is not required when you call the JSReports Console App API
    {
    "renderRequest":{
    "template":{"name": "XXJobSchedule", "shortid": "xxx56p", "recipe": "html"},
    "options":{"reports":{"save":true} },
    "data": {
    .....
    }
    }
    }


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.