Basic support for uploading Node.js function
Pre-releaseAdded basic support for uploading Node.js function with zip-archived artifact.
- Install Node.js, verify npm is also available
- Install NodeJS plugin to the IntelliJ IDEA: start the IntelliJ IDEA, open Preferences, navigate to the Plugins tab, hit the "Browse repositories..." button, search and select NodeJS, hit "Install" button and then "Restart IDEA" to apply changes.
- On you disk - create a folder for a project for the Node.js AWS Lambda function, navigate to this folder
- run commands to install aws-sdk modules and create empty file "index.js" within "src" folder
npm install aws-sdk
mkdir src
touch src/index.js
(in Windows instead of "touch": echo "" > src/index.js )
- In IntelliJ IDEA open the project, selecting the folder, created above
- In the index file copy paste the code:
exports.handler = (event, context, callback) => {
callback(null, "some success message with a name " + event.name);
// or
// callback("some error type");
}
-
Open the Project Structure, select Artifacts section on the left
-
Hit the "+" button to add a new artifact, choose a type "Other"
-
Specify a name of the artifact, optionally - tick the checkbox "Include in the project build"
-
In the "Output Layout" tab - hit the icon "Create Archive" (a second one next to the icon "Folder with +")
-
In the dialog - enter the archive name, with an extension ".zip", hit "Ok"
-
Right click on the added archive-name, in the menu - select "Create Directory", enter "node_modules", hit "Ok"
-
Right click on the added directory name, in the menu - select "Add Copy of", select "Directory Content", choose the folder "node_modules" in the project's folder, hit "Open"
-
Similar way - add a reference to the folder "src" in the project's folder
-
Right click on the archive-name, in the menu - select "Add Copy of", select "File", choose a file "package-lock.json" in the project's folder, hit "Open"
-
Rebuld the project and an artifact (if not build automatically). Check if the artifact contains the file in the "out" folder of the project
-
Refresh the "Artifacts" list in the "Connector for AWS Lambda" plugin tab, select the artifact and a function (with NodeJS runtime), where it should be uploaded
-
In the "Handler" field - enter "src/index.handler", where "src" is a project's folder "src" (if used), "index" - the name of the js-file, where the function is located, "handler" - a name of JavaScript funtion (in this example it is second part of "exports.handler")
-
Hit the button "Upload function" in the plugin form
-
Test the function - open the "Run Test" tab, hit the button "Run test of the function"