Skip to content

ecgouvea/aws-lambda-apigw-serverlessfmk-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AWS Lambda Serverless Project

This project is a serverless application built using the Serverless Framework. It handles AWS API Gateway events and processes them through a Lambda function.

Project Structure

aws-lambda-serverless
├── src
│   ├── handler.js          # Main entry point for the AWS Lambda function
│   └── utils
│       └── helper.js       # Utility functions for the handler
├── serverless.yml          # Serverless Framework configuration
├── package.json             # npm configuration and dependencies
├── .gitignore               # Git ignore file
└── README.md                # Project documentation

Setup Instructions

  1. Clone the repository:

    git clone <repository-url>
    cd aws-lambda-serverless
    
  2. Install dependencies:

    npm install
    
  3. Deploy the service:

    serverless deploy
    
  4. Invoke the function:

    serverless invoke -f <function-name>
    
  5. Remove the service:

    serverless remove
    

Usage

This project is designed to handle API Gateway events. The main function is located in src/handler.js, and it processes incoming requests and returns appropriate responses.

Test it

Execute:

$ curl -v -X POST  http://localhost:3000/api  -d '{"msg":"abc"}' | /c/Users/eduardo.gouvea/.nvm/versions/node/v20.17.0/bin/node_modules/node-jq/bin/jq.exe

Response should be:

> POST /api HTTP/1.1
> Host: localhost:3000
> User-Agent: curl/8.1.2
> Accept: */*
> Content-Length: 13
> Content-Type: application/x-www-form-urlencoded
>
} [13 bytes data]
< HTTP/1.1 200 OK
< content-type: application/json; charset=utf-8
< cache-control: no-cache
< content-length: 829
< Date: Mon, 31 Mar 2025 14:18:42 GMT
< Connection: keep-alive
< Keep-Alive: timeout=5
<
{ [829 bytes data]
100   842  100   829  100    13   3496     54 --:--:-- --:--:-- --:--:--  3537
* Connection #0 to host localhost left intact
{
  "message": "Hello from AWS Lambda!",
  "input": {
    "body": "{\"msg\":\"abc\"}",
    "cookies": [],
    "headers": {
      "host": "localhost:3000",
      "user-agent": "curl/8.1.2",
      "accept": "*/*",
      "content-length": "13",
      "content-type": "application/x-www-form-urlencoded"
    },
    "isBase64Encoded": false,
    "pathParameters": null,
    "queryStringParameters": null,
    "rawPath": "/api",
    "rawQueryString": "",
    "requestContext": {
      "accountId": "offlineContext_accountId",
      "apiId": "offlineContext_apiId",
      "domainName": "offlineContext_domainName",
      "domainPrefix": "offlineContext_domainPrefix",
      "http": {
        "method": "POST",
        "path": "/api",
        "protocol": "HTTP/1.1",
        "sourceIp": "::1",
        "userAgent": "curl/8.1.2"
      },
      "requestId": "offlineContext_resourceId",
      "routeKey": "POST api",
      "stage": "$default",
      "time": "31/Mar/2025:11:18:42 -0300",
      "timeEpoch": 1743430722590
    },
    "routeKey": "POST api",
    "stageVariables": null,
    "version": "2.0"
  }
}

Contributing

Feel free to submit issues or pull requests for improvements or bug fixes.

License

This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published