So far, we used the web based editor but that's of course not how larger applications are developed. We want to use a local IDE and then deploy to Lambda. Usually this is even a necessity as much of Node.js power lies in the huge number of npm modules available and they can not be installed to a project via AWS console.
In this lab we will prepare, bundle and upload the same REST API we used on the console before.
-
Open Visual Studio Code and this repository.
-
In the integrated terminal, change to
projects/rest-api
-
While we are at it let's bring in the Dynatrace agent by running
npm install --save @dynatrace/oneagent@next
.By using
@next
we are making sure that we get the very latest agent version. -
The agent npm module contains pre-compiled versions for many platforms and Node.js versions. We should trim it down to what we actually need - and that's Node.js 8.10 on Linux. The npm module comes with a script that does exactly that.
In the integrated terminal, run
npx dt-oneagent-tailor --AwsLambdaV8
to trim the agent down. It should terminate withSUCCEEDED
and the overall project size should be around 4 times smaller than before. -
To upload the package to AWS, we need to ZIP it first. A common pitfall is to ZIP the whole folder, which creates a nested folder when uploaded to AWS. We have to make sure that the ZIP only contains the files and not the folder they are contained in locally.
On Mac or Linux
- use the integrated terminal and run
zip -r ../rest-api-deploy.zip .
f from the project directory.
On Windows
- open the File Explorer
- change into the project directory
- select all files
- click right
- choose
Send to
and chooseCompressed (zipped)
folder and enterrest-api-deploy.zip
as filename.
- use the integrated terminal and run
-
Open the AWS console and the previously created
HotDayRestMicroservice
function and now choose Upload a ZIP File in theFunction code
section. -
Select the deployment ZIP and click
Save
-
Let's use postman to do a quick test to see if everything still works
⬆️ Back to TOC