Skip to content

Commit dcda15f

Browse files
authored
Merge pull request serverless#7 from serverless/babel-example
Babel example
2 parents b2b229b + 232b0c6 commit dcda15f

File tree

8 files changed

+130
-10
lines changed

8 files changed

+130
-10
lines changed

.eslintrc.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "airbnb-base",
3+
"env": {
4+
"node": true
5+
},
6+
"rules": {
7+
"strict": "off",
8+
"import/no-unresolved": "off"
9+
}
10+
}
+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Function compiled with Babel
2+
3+
This example demonstrates how to compile your JavaScript code with Babel. In order to do so the `serverless-babel-plugin` is leveraged.
4+
5+
## Use Cases
6+
7+
- Using the latest JavaScript language features without waiting for AWS to provide new Node environments.
8+
9+
## Setup
10+
11+
```bash
12+
npm install
13+
```
14+
15+
## Deploy
16+
17+
```bash
18+
serverless deploy
19+
```
20+
21+
```bash
22+
Serverless: Deprecation Notice: Starting with the next update, we will drop support for Lambda to implicitly create LogGroups. Please remove your log groups and set "provider.cfLogs: true", for CloudFormation to explicitly create them for you.
23+
Serverless: Packaging service…
24+
Serverless: Babel compilation:
25+
tmpBabelDirectory/createResponse.js -> tmpBabelDirectory/createResponse.js
26+
tmpBabelDirectory/handler.js -> tmpBabelDirectory/handler.js
27+
28+
Serverless: Packaging service with compiled files...
29+
Serverless: Uploading CloudFormation file to S3…
30+
Serverless: Uploading service .zip file to S3…
31+
Serverless: Updating Stack…
32+
Serverless: Checking Stack update progress…
33+
............
34+
Serverless: Stack update finished…
35+
36+
Service Information
37+
service: function-compiled-with-babel
38+
stage: dev
39+
region: us-east-1
40+
api keys:
41+
None
42+
endpoints:
43+
None
44+
functions:
45+
function-compiled-with-babel-dev-hello: arn:aws:lambda:us-east-1:377024778620:function:function-compiled-with-babel-dev-hello
46+
```
47+
48+
## Usage
49+
50+
You can now invoke the Lambda directly and even see the resulting log via
51+
52+
```bash
53+
serverless invoke --function hello --log
54+
```
55+
56+
The expected result should be similar to:
57+
58+
```bash
59+
{
60+
"statusCode": 200,
61+
"body": {
62+
"message": "Success!"
63+
}
64+
}
65+
--------------------------------------------------------------------
66+
START RequestId: 4388ee49-affe-11e6-9e69-1bde31ed2e43 Version: $LATEST
67+
2016-11-21 16:22:07.748 (+01:00) 4388ee49-affe-11e6-9e69-1bde31ed2e43 { response: { statusCode: 200, body: { message: 'Success!' } } }
68+
END RequestId: 4388ee49-affe-11e6-9e69-1bde31ed2e43
69+
REPORT RequestId: 4388ee49-affe-11e6-9e69-1bde31ed2e43 Duration: 23.13 ms Billed Duration: 100 ms Memory Size: 1024 MB Max Memory Used: 17 MB
70+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = ({ body = {}, statusCode = 200 }) => {
2+
const response = {
3+
statusCode,
4+
body,
5+
};
6+
return response;
7+
};
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"key3": "value3",
3+
"key2": "value2",
4+
"key1": "value1"
5+
}
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const createResponse = require('./createResponse');
2+
3+
module.exports.hello = (event, context, callback) => {
4+
const response = createResponse({ body: { message: 'Success!' } });
5+
console.log({ response }); // eslint-disable-line no-console
6+
callback(null, response);
7+
};
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "function-compiled-with-babel",
3+
"version": "1.0.0",
4+
"description": "Demonstrating how to compile all your code with Babel",
5+
"repository": "<replace>",
6+
"author": "",
7+
"license": "MIT",
8+
"devDependencies": {
9+
"babel-preset-latest": "^6.16.0",
10+
"serverless-babel-plugin": "^0.1.0"
11+
},
12+
"dependencies": {}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
service: function-compiled-with-babel
2+
3+
frameworkVersion: ">=1.1.0 <2.0.0"
4+
5+
custom:
6+
babelPresets:
7+
- latest
8+
9+
plugins:
10+
- serverless-babel-plugin
11+
12+
provider:
13+
name: aws
14+
runtime: nodejs4.3
15+
16+
functions:
17+
hello:
18+
handler: handler.hello

package.json

-10
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,5 @@
1010
"eslint": "^3.10.0",
1111
"eslint-config-airbnb-base": "^10.0.1",
1212
"eslint-plugin-import": "^2.2.0"
13-
},
14-
"eslintConfig": {
15-
"extends": "airbnb-base",
16-
"env": {
17-
"node": true
18-
},
19-
"rules": {
20-
"strict": "off",
21-
"import/no-unresolved": "off"
22-
}
2313
}
2414
}

0 commit comments

Comments
 (0)