As I have used the serverless structure for my Node application and wanted to implement the jsreport 2.10.1 to download my reports oriented things.
I have configured all regarding the jsreport configurations
const jsreport = require("jsreport-core")({
rootDirectory: __dirname,
});
jsreport.use(require("jsreport-handlebars")());
jsreport.use(require("jsreport-chrome-pdf")());
jsreport.use(require("jsreport-html-to-xlsx")());
jsreport.use(
require("jsreport-assets")({
searchOnDiskIfNotFoundInStore: true,
allowedFiles: "**/*.*",
})
);
jsreport.init();
export default class DownloadService {
constructor() {
// Empty Constructor
}
async generateFile(module: String, datas: any, template: any) {
try {
return jsreport
.render({
template: template,
data: datas,
})
.then((resp: Record<string, unknown>) => {
const content = { content: resp.content } as Record<string, unknown>;
content.reportname =
(module ? module : "download") +
(template.recipe == "chrome-pdf" ? ".pdf" : ".XLSX");
return {
success: true,
message: "Template and data binded successfully",
data: content,
};
})
.catch((error) => {
return {
success: false,
message: error.message,
};
});
} catch (err) {
return Promise.reject({
success: false,
message: `internal error is ${err}`,
code: 500,
});
}
}
}
I have used layers to pack all dependencies and I have mentioned here:
{
"name": "testlambda",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"pg": "^8.10.0",
"pg-native": "^3.0.1",
"axios": "^1.3.4",
"jsreport-assets": "^1.7.0",
"jsreport-chrome-pdf": "^1.10.0",
"jsreport-core": "^2.10.1",
"jsreport-handlebars": "^2.1.0",
"jsreport-html-to-xlsx": "^2.6.0",
"jsreport-phantom-pdf": "^2.6.1",
"should": "^13.2.3",
"emitter": "^0.0.5"
},
"devDependencies": {
"aws-lambda": "^1.0.7"
}
}
When I call one endpoint invoice-generate, I just implement my logic and call this generateFile object and that works properly in my local machine.
When I deployed same on AWS lambda using serverless.js file there apps gets crash and throws like below:
I found this in my cloud watcher.
I'm not sure what I missed and what is the root cause of this.
Folks please provide me a any insights to fix this and make this run successfully on my Lambda function.
Below is the my serverless.js lambda function configurations.
serverHandler:
handler: dist/index.server
timeout: 600
events:
- http:
path: /
method: ANY
cors:
origin: "*"
headers: ${self:custom.allowed-headers}
allowCredentials: true
- http:
path: /{proxy+}
method: ANY
cors:
origin: "*"
headers: ${self:custom.allowed-headers}
allowCredentials: true
authorizer: ${self:custom.authorizer.cognito_authorizer}
iamRoleStatementsName: "EVCognitoAdminRole${opt:stage}"
iamRoleStatements:
- Effect: Allow
Action:
- "cognito-idp:AdminUserGlobalSignOut"
- "cognito-idp:AddCustomAttributes"
- "cognito-idp:AdminCreateUser"
- "cognito-idp:AdminSetUserPassword"
- "cognito-idp:AdminSetUserSettings"
- "cognito-idp:AdminAddUserToGroup"
- "cognito-idp:GetGroup"
- "cognito-idp:AdminGetUser"
- "cognito-idp:AdminConfirmSignUp"
- "cognito-idp:AdminEnableUser"
- "cognito-idp:AdminListUserAuthEvents"
- "cognito-idp:UpdateGroup"
- "cognito-idp:AdminInitiateAuth"
- "cognito-idp:AdminDisableUser"
- "cognito-idp:AdminRemoveUserFromGroup"
- "cognito-idp:AdminResetUserPassword"
- "cognito-idp:AdminUpdateUserAttributes"
Resource:
- !GetAtt cognitoUserPool.Arn
- Effect: Allow
Action:
- "sns:SetSMSAttributes"
- "sns:Publish"
Resource: "*"
- Effect: "Allow"
Action:
- "s3:GetObject"
- "s3:PutObject"
- "s3:PutObjectAcl"
- "s3:AbortMultipartUpload"
- "s3:DeleteObject"
Resource: "arn:aws:s3:::${self:custom.publicBucketName}"
I have tried all the debugging inside the nodemodules also and i cant find the root cause or solution for this. i wish to know about this solution