Coder Social home page Coder Social logo

aws-lambda's Introduction

AWS Lambda em Typescript com Serverless Framework

Função Lambda simples em Typescript usando o Serverless Framework para implantar.

https://docs.aws.amazon.com/lambda/latest/dg/lambda-nodejs.html

Desenvolvimento

$ serverless create --template aws-nodejs --path serverless-typescript
$ npm install -D serverless-plugin-typescript typescript
$ npm install -D serverless-offline

$ serverless invoke local --function serverlessTypescript --log
$ serverless offline start

Implantar

$ serverless deploy

O resultado esperado deve ser semelhante a:

Serverless: Compiling with Typescript...
Serverless: Using local tsconfig.json
handler.ts (1,25): Cannot find module 'aws-lambda' or its corresponding type declarations.
Serverless: Typescript compiled.
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Creating Stack...
Serverless: Checking Stack create progress...
........
Serverless: Stack create finished...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service serverless-typescript.zip file to S3 (13.92 MB)...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
..............................
Serverless: Stack update finished...
Service Information
service: serverless-typescript
stage: dev
region: eu-central-1
stack: serverless-typescript-dev
resources: 11
api keys:
  None
endpoints:
  GET - https://m92rf2g2j4.execute-api.eu-central-1.amazonaws.com/dev/
functions:
  serverlessTypescript: serverless-typescript-dev-serverlessTypescript
layers:
  None

Uso

Agora você pode invocar a função Lambda diretamente e até mesmo ver o log resultante via

serverless invoke --function serverlessTypescript --log

O resultado esperado deve ser semelhante a:

{
    "statusCode": 200,
    "body": "{\n  \"message\": \"Hello Serverless Typescript.\",\n  \"input\": {}\n}"
}
--------------------------------------------------------------------
START RequestId: 1aa539db-6ec8-4be7-9f6d-3492811b82e7 Version: $LATEST
END RequestId: 1aa539db-6ec8-4be7-9f6d-3492811b82e7
REPORT RequestId: 1aa539db-6ec8-4be7-9f6d-3492811b82e7	Duration: 2.40 ms	Billed Duration: 100 ms	Memory Size: 512 MB	Max Memory Used: 65 MB	Init Duration: 152.52 ms

Finalmente, você pode enviar uma solicitação HTTP diretamente para o endpoint usando uma ferramenta como curl ou HTTPie

$ http get https://XXXXXXXXXX.execute-api.eu-central-1.amazonaws.com/dev/serverless-typescript

aws-lambda's People

Contributors

fabio-silva458 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.