Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

aws-serverless-express

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aws-serverless-express - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

60

index.js

@@ -23,3 +23,3 @@ /*

const queryStringParams = queryStringKeys.map(queryStringKey => `${queryStringKey}=${event.queryStringParameters[queryStringKey]}`).join('&')
const queryStringParams = queryStringKeys.map(queryStringKey => `${queryStringKey}=${encodeURIComponent(event.queryStringParameters[queryStringKey])}`).join('&')

@@ -30,6 +30,5 @@ return `${event.path}?${queryStringParams}`

function mapApiGatewayEventToHttpRequest(event, context, socketPath) {
const headers = event.headers || {}
const headers = event.headers || {} // NOTE: Mutating event.headers; prefer deep clone of event.headers
const eventWithoutBody = Object.assign({}, event)
delete eventWithoutBody['body']
delete eventWithoutBody.body

@@ -52,18 +51,31 @@ headers['x-apigateway-event'] = JSON.stringify(eventWithoutBody)

function forwardResponseToApiGateway(server, response, context) {
let body = ''
let buf = []
response.setEncoding('utf8')
.on('data', (chunk) => body += chunk.toString('utf8'))
.on('end', () => {
const statusCode = response.statusCode
const headers = response.headers
response
.on('data', (chunk) => buf.push(chunk))
.on('end', () => {
let body = Buffer.concat(buf)
const statusCode = response.statusCode
const headers = response.headers
Object.keys(headers)
.forEach(h => {
if(Array.isArray(headers[h])) headers[h] = headers[h].join(',')
Object.keys(headers)
.forEach(h => {
if(Array.isArray(headers[h])) headers[h] = headers[h].join(',')
})
const contentType = headers['content-type']
let isBase64Encoded
if (server._binaryTypes.indexOf(contentType) !== -1) {
body = body.toString('base64')
isBase64Encoded = true
} else {
body = body.toString('utf8')
isBase64Encoded = false
}
const successResponse = {statusCode, body, headers, isBase64Encoded}
context.succeed(successResponse)
})
const successResponse = {statusCode, body, headers}
context.succeed(successResponse)
})
}

@@ -113,6 +125,7 @@

exports.createServer = (requestListener, serverListenCallback) => {
exports.createServer = (requestListener, serverListenCallback, binaryTypes) => {
const server = http.createServer(requestListener)
server._socketPathSuffix = 0
server._binaryTypes = binaryTypes ? binaryTypes.slice() : []
server.on('listening', () => {

@@ -155,1 +168,12 @@ server._isListening = true

}
if (process.env.NODE_ENV === 'test') {
exports.getPathWithQueryStringParams = getPathWithQueryStringParams
exports.mapApiGatewayEventToHttpRequest = mapApiGatewayEventToHttpRequest
exports.forwardResponseToApiGateway = forwardResponseToApiGateway
exports.forwardConnectionErrorResponseToApiGateway = forwardConnectionErrorResponseToApiGateway
exports.forwardLibraryErrorResponseToApiGateway = forwardLibraryErrorResponseToApiGateway
exports.forwardRequestToNodeServer = forwardRequestToNodeServer
exports.startServer = startServer
exports.getSocketPath = getSocketPath
}
{
"name": "aws-serverless-express",
"version": "1.2.0",
"version": "1.3.0",
"description": "This library enables you to utilize AWS Lambda and Amazon API Gateway to respond to web and API requests using your existing Node.js application framework.",

@@ -29,3 +29,9 @@ "keywords": [

"node": ">=4"
},
"devDependencies": {
"jest": "^16.0.2"
},
"scripts": {
"test": "jest"
}
}

@@ -32,3 +32,3 @@ This library enables you to utilize [AWS Lambda](https://aws.amazon.com/lambda/) and [Amazon API Gateway](https://aws.amazon.com/api-gateway/) to respond to web and API requests using your existing [Node.js](https://nodejs.org/) application framework. The sample provided allows you to easily build serverless web applications/services and RESTful APIs using the [Express](https://expressjs.com/) framework.

1. From your preferred project directory: `git clone https://github.com/awslabs/aws-serverless-express.git && cd aws-serverless-express/example`.
2. Run `npm run config <accountId> <bucketName> [region]` to configure the example, eg. `npm run config 123456789012 my-bucket us-west-2`. This modifies `package.json` and `simple-proxy-api.yaml` with your account ID, bucket, and region (region defaults to `us-east-1`). If the bucket you specify does not yet exist, the next step will create it for you. This step modifies the existing files in-place; if you wish to make changes to these settings, you will need to modify `package.json` and `simple-proxy-api.yaml` manually.
2. Run `npm run config -- --account-id="<accountId>" --bucket-name="<bucketName>" [--region="<region>" --function-name="<functionName>"]` to configure the example, eg. `npm run config -- --account-id="123456789012" --bucket-name="my-bucket" --region="us-west-2" --function-name="my-function"`. This modifies `package.json`, `simple-proxy-api.yaml` and `cloudformation.json` with your account ID, bucket, region and function name (region defaults to `us-east-1` and function name defaults to `AwsServerlessExpressFunction`). If the bucket you specify does not yet exist, the next step will create it for you. This step modifies the existing files in-place; if you wish to make changes to these settings, you will need to modify `package.json`, `simple-proxy-api.yaml` and `cloudformation.json` manually.
3. Run `npm run setup` (Windows users: `npm run win-setup`) - this installs the node dependencies, creates the S3 bucket (if it does not already exist), packages and uploads your serverless Express application assets to S3, uploads the API Swagger file to S3, and finally spins up a CloudFormation stack, which creates your API Gateway API and Lambda Function.

@@ -50,3 +50,3 @@ 4. After the setup command completes, open the AWS CloudFormation console https://console.aws.amazon.com/cloudformation/home and switch to the region you specified. Select the `AwsServerlessExpressStack` stack, and wait several minutes for the status to change to `CREATE_COMPLETE`, then click the `ApiUrl` value under the __Outputs__ section - this will open a new page with your running API. The API index lists the resources available in the example Express server (`app.js`), along with example `curl` commands.

2. From your existing project directory, run `npm install --save aws-serverless-express`.
3. Modify `lambda.js` to import your own server configuration (eg. change `require('./app')` to `require('./app')`). You will need to ensure you export your app configuration from the necessary file (eg. `module.exports = app`). This library takes your app configuration and listens on a Unix Domain Socket for you, so you can remove your call to `app.listen()` (if you have a `server.listen` callback, you can provide it as the second parameter in the `awsServerlessExpress.createServer` method).
3. Modify `lambda.js` to import your own server configuration (eg. change `require('./app')` to `require('./server')`). You will need to ensure you export your app configuration from the necessary file (eg. `module.exports = app`). This library takes your app configuration and listens on a Unix Domain Socket for you, so you can remove your call to `app.listen()` (if you have a `server.listen` callback, you can provide it as the second parameter in the `awsServerlessExpress.createServer` method).
4. Modify the `package-function` script (`win-package-function` for Windows users) in `package.json` to include all files necessary to run your application. If everything you need is in a single child directory, this is as simple as changing `app.js` to `my-app-dir` (also remove `index.html` from that command). If you are using a build tool, you will instead want to add your build output directory to this command.

@@ -57,3 +57,3 @@ 5. Run `npm run package-upload-update-function` (Windows users: `npm run win-package-upload-update-function`) to package (zip), upload (to S3), and update your Lambda function.

If you need to make modifications to your API Gateway API, modify `simple-proxy-api.yaml` and run `npm run upload-api-gateway-swagger && npm run update stack`. If your API requires CORS, be sure to modify the two `options` methods defined in the Swagger file, otherwise you can safely remove them. Note: there is currently an issue with updating CloudFormation when it's not obvious that one of its resources has been modified; eg. the Swagger file is an external file hosted on S3. To work around this, simply update one of the resource's properties, such as the `Description` on the `ApiGatewayApi` resource. To modify your other AWS assets, make your changes to `cloudformation.json` and run `npm run update-stack`. Alternatively, you can manage these assets via the AWS console.
If you need to make modifications to your API Gateway API, modify `simple-proxy-api.yaml` and run `npm run upload-api-gateway-swagger && npm run update-stack`. If your API requires CORS, be sure to modify the two `options` methods defined in the Swagger file, otherwise you can safely remove them. Note: there is currently an issue with updating CloudFormation when it's not obvious that one of its resources has been modified; eg. the Swagger file is an external file hosted on S3. To work around this, simply update one of the resource's properties, such as the `Description` on the `ApiGatewayApi` resource. To modify your other AWS assets, make your changes to `cloudformation.json` and run `npm run update-stack`. Alternatively, you can manage these assets via the AWS console.

@@ -90,3 +90,2 @@ ### Getting the API Gateway event object

- Multiple headers with same name not supported
- Currently no support for binary data
- API Gateway has a timeout of 30 seconds, and Lambda has a maximum execution time of 5 minutes.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc