[AWS Lambda] including dependencies in your AWS Lambda function

Source: Internet
Author: User
Tags zip folder

This lesson teaches the use of dependencies, such as faker.js in your LAMBDA functions. We'll update the lambda code from the lambda and API Gateway lesson to generate random work history and endorsements USI ng The Faker npm module then upload our code to LAMBDA and test.

When you code has dependencies. You cannot just write code in AWS inline editor. You have to zip your code and upload to the AWS.

Index.js:

varFaker = require ('Faker'); Exports.handler= function (Event, context) {    varCareer = {}; Career.firstname=Event. FirstName; Career.lastname=Event. LastName; Career.socialmedianame=Getsocialmedianame (); Career.careerhistory= [];  for(vari =0; i<5; i++){        varCompany = {}; Company.companyname=Getcompanyname (); Company.desc=Getcompanydesc (); Company.companytitle=GetTitle (); Company.startdate=getDate (); Company.city=getcity (); Company.state=getState (); Company.country=Getcountry ();    Career.careerHistory.push (company); } career.endorsements= [];  for(vari =0; i< -; i++) {Career.endorsements.push (getendorsement ()); } context.succeed (career);}; function Getsocialmedianame () {returnfaker.internet.userName ();} function Getcompanyname () {returnfaker.company.companyName ();} function Getcompanydesc () {returnfaker.company.bs ();} function GetTitle () {returnFaker.company.bsAdjective () +" "+ faker.company.bsAdjective () +" "+Faker.company.bsNoun ();} function GetDate () {returnfaker.date.past ();} function getcity () {returnfaker.address.city ();} function GetState () {returnfaker.address.state ();} function Getcountry () {returnfaker.address.country ();} function Getendorsement () {returnfaker.company.catchPhrase ();}

Zip index.js and Node_modules folder into a zip folder, then upload to the LAMBDA, save and test. It may report some error, but if your test from Postman, if it works if it fine.

[AWS Lambda] including dependencies in your AWS Lambda function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.