Skip to content

Commit

Permalink
chore: test node20
Browse files Browse the repository at this point in the history
  • Loading branch information
juanjoDiaz committed Nov 29, 2023
1 parent 1a80dcf commit 178ad0f
Show file tree
Hide file tree
Showing 10 changed files with 265 additions and 0 deletions.
6 changes: 6 additions & 0 deletions test-integration/aws-node-http-api-project/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# package directories
node_modules
jspm_packages

# Serverless directories
.serverless
92 changes: 92 additions & 0 deletions test-integration/aws-node-http-api-project/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<!--
title: 'AWS Simple HTTP Endpoint example in NodeJS'
description: 'This template demonstrates how to make a simple HTTP API with Node.js running on AWS Lambda and API Gateway using the Serverless Framework.'
layout: Doc
framework: v3
platform: AWS
language: nodeJS
authorLink: 'https://github.com/serverless'
authorName: 'Serverless, inc.'
authorAvatar: 'https://avatars1.githubusercontent.com/u/13742415?s=200&v=4'
-->

# Serverless Framework Node HTTP API on AWS

This template demonstrates how to make a simple HTTP API with Node.js running on AWS Lambda and API Gateway using the Serverless Framework.

This template does not include any kind of persistence (database). For more advanced examples, check out the [serverless/examples repository](https://github.com/serverless/examples/) which includes Typescript, Mongo, DynamoDB and other examples.

## Usage

### Deployment

```
$ serverless deploy
```

After deploying, you should see output similar to:

```bash
Deploying aws-node-http-api-project to stage dev (us-east-1)

✔ Service deployed to stack aws-node-http-api-project-dev (152s)

endpoint: GET - https://xxxxxxxxxx.execute-api.us-east-1.amazonaws.com/
functions:
hello: aws-node-http-api-project-dev-hello (1.9 kB)
```

_Note_: In current form, after deployment, your API is public and can be invoked by anyone. For production deployments, you might want to configure an authorizer. For details on how to do that, refer to [http event docs](https://www.serverless.com/framework/docs/providers/aws/events/apigateway/).

### Invocation

After successful deployment, you can call the created application via HTTP:

```bash
curl https://xxxxxxx.execute-api.us-east-1.amazonaws.com/
```

Which should result in response similar to the following (removed `input` content for brevity):

```json
{
"message": "Go Serverless v2.0! Your function executed successfully!",
"input": {
...
}
}
```

### Local development

You can invoke your function locally by using the following command:

```bash
serverless invoke local --function hello
```

Which should result in response similar to the following:

```
{
"statusCode": 200,
"body": "{\n \"message\": \"Go Serverless v3.0! Your function executed successfully!\",\n \"input\": \"\"\n}"
}
```


Alternatively, it is also possible to emulate API Gateway and Lambda locally by using `serverless-offline` plugin. In order to do that, execute the following command:

```bash
serverless plugin install -n serverless-offline
```

It will add the `serverless-offline` plugin to `devDependencies` in `package.json` file as well as will add it to `plugins` in `serverless.yml`.

After installation, you can start local emulation with:

```
serverless offline
```

To learn more about the capabilities of `serverless-offline`, please refer to its [GitHub repository](https://github.com/dherault/serverless-offline).
11 changes: 11 additions & 0 deletions test-integration/aws-node-http-api-project/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const handler = async (event) => {
// TODO implement
const response = {
statusCode: 200,
body: JSON.stringify({
message: 'Hello from Lambda!',
event
}),
};
return response;
};
21 changes: 21 additions & 0 deletions test-integration/aws-node-http-api-project/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions test-integration/aws-node-http-api-project/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "aws-node-http-api-project",
"version": "1.0.0",
"description": "<!-- title: 'AWS Simple HTTP Endpoint example in NodeJS' description: 'This template demonstrates how to make a simple HTTP API with Node.js running on AWS Lambda and API Gateway using the Serverless Framework.' layout: Doc framework: v3 platform: AWS language: nodeJS authorLink: 'https://github.com/serverless' authorName: 'Serverless, inc.' authorAvatar: 'https://avatars1.githubusercontent.com/u/13742415?s=200&v=4' -->",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"serverless-plugin-warmup": "^8.2.1"
}
}
22 changes: 22 additions & 0 deletions test-integration/aws-node-http-api-project/serverless.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
service: aws-node-http-api-project
frameworkVersion: '3'

provider:
name: aws
runtime: nodejs20.x

custom:
warmup:
default:
enabled: true

functions:
api:
handler: index.handler
events:
- httpApi:
path: /
method: get

plugins:
- serverless-plugin-warmup
6 changes: 6 additions & 0 deletions test-integration/aws-node-project/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# package directories
node_modules
jspm_packages

# Serverless directories
.serverless
72 changes: 72 additions & 0 deletions test-integration/aws-node-project/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<!--
title: 'AWS NodeJS Example'
description: 'This template demonstrates how to deploy a NodeJS function running on AWS Lambda using the traditional Serverless Framework.'
layout: Doc
framework: v3
platform: AWS
language: nodeJS
priority: 1
authorLink: 'https://github.com/serverless'
authorName: 'Serverless, inc.'
authorAvatar: 'https://avatars1.githubusercontent.com/u/13742415?s=200&v=4'
-->


# Serverless Framework AWS NodeJS Example

This template demonstrates how to deploy a NodeJS function running on AWS Lambda using the traditional Serverless Framework. The deployed function does not include any event definitions as well as any kind of persistence (database). For more advanced configurations check out the [examples repo](https://github.com/serverless/examples/) which includes integrations with SQS, DynamoDB or examples of functions that are triggered in `cron`-like manner. For details about configuration of specific `events`, please refer to our [documentation](https://www.serverless.com/framework/docs/providers/aws/events/).

## Usage

### Deployment

In order to deploy the example, you need to run the following command:

```
$ serverless deploy
```

After running deploy, you should see output similar to:

```bash
Deploying aws-node-project to stage dev (us-east-1)

✔ Service deployed to stack aws-node-project-dev (112s)

functions:
hello: aws-node-project-dev-hello (1.5 kB)
```

### Invocation

After successful deployment, you can invoke the deployed function by using the following command:

```bash
serverless invoke --function hello
```

Which should result in response similar to the following:

```json
{
"statusCode": 200,
"body": "{\n \"message\": \"Go Serverless v3.0! Your function executed successfully!\",\n \"input\": {}\n}"
}
```

### Local development

You can invoke your function locally by using the following command:

```bash
serverless invoke local --function hello
```

Which should result in response similar to the following:

```
{
"statusCode": 200,
"body": "{\n \"message\": \"Go Serverless v3.0! Your function executed successfully!\",\n \"input\": \"\"\n}"
}
```
11 changes: 11 additions & 0 deletions test-integration/aws-node-project/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports.handler = async (event) => ({
statusCode: 200,
body: JSON.stringify(
{
message: 'Go Serverless v3.0! Your function executed successfully!',
input: event,
},
null,
2,
),
});
10 changes: 10 additions & 0 deletions test-integration/aws-node-project/serverless.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
service: aws-node-project
frameworkVersion: '3'

provider:
name: aws
runtime: nodejs18.x

functions:
function1:
handler: index.handler

0 comments on commit 178ad0f

Please sign in to comment.