Expand my Community achievements bar.

SOLVED

How can we use modules inside runtime action?

Avatar

Level 2

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

 

1 Accepted Solution

Avatar

Correct answer by
Level 2

Hi @Aditya82Ram ,

 

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

 

Thanks

Naveen

View solution in original post

6 Replies

Avatar

Level 1

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!

 

Avatar

Correct answer by
Level 2

Hi @Aditya82Ram ,

 

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

 

Thanks

Naveen

Avatar

Level 1

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!

Avatar

Level 2

I guess it will work, first you need to install aws-sdk in your app folder node_modules and in index.js you can utilize. 

You can invoke this web-actions using api call. 

Avatar

Employee

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.