How can we use modules inside runtime action? | Community
Skip to main content
Level 2
August 10, 2021
Solved

How can we use modules inside runtime action?

  • August 10, 2021
  • 1 reply
  • 2517 views

Hi,

 

I tried to create action with below code.

 

function main(params) {

//var test = async function() {
const adobeIOSdk = require('@adobe/aio-sdk')
//const presignUrl = await files.generatePresignURL('mydir/myfile.txt', { expiryInSeconds: 60 })
const presignUrl = 'test'
//return presignUrl
//}
return {
statusCode: 200,
body: {
payload: presignUrl
}
}
}

 

but when I invoke got an error saying like below.

An error has occurred: Error: Cannot find module '@adobe/aio-sdk'\nRequire stack:\n- /nodejsAction/runner.js\n- /nodejsAction/src/service.js\n- /nodejsAction/app.js

 

 

Thanks

Naveen

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Naveen_Srinivas

Hi @aditya82ram ,

 

You have to deploy your action under headless application. https://www.adobe.io/project-firefly/docs/overview/firefly_and_runtime/

 

Thanks

Naveen

1 reply

August 24, 2021

Hi @naveen_srinivas,

 

I am facing a similar issue - trying to access S3 files that requires aws-sdk module. 

I am wondering if packages can be used to circumvent the local dependency issue. 

 

I look forward to hearing your take on this. Alternatively please feel free to let me know of any other ideas you may have around this.

 

Cheers!

 

Naveen_SrinivasAuthorAccepted solution
Level 2
August 24, 2021

Hi @aditya82ram ,

 

You have to deploy your action under headless application. https://www.adobe.io/project-firefly/docs/overview/firefly_and_runtime/

 

Thanks

Naveen

Adobe Employee
August 24, 2021

Hi @naveen_srinivas,

 

Thank you for sharing this. I will explore further into this.

Quick question though: is this approach applicable to non-Adobe products as well?

 

I need to access a file in S3; my JavaScript code requires aws-sdk (instead of aio-sdk, in your case). Does the headless application method you suggested work for any module, or is it specific to only Adobe-related products.

 

Thanks!

P.S. Please don't mind if I have incorrectly stated something - I am learning JavaScript on the job!


What @naveen_srinivas mentioned is our recommendation as well.

Writing your Runtime actions in the Project Firefly structure will help to build and deploy your code automatically, without much effort for adding custom modules.

You only need to add the required modules in package.json, and run npm install.

This applies to non-Adobe modules as well.