Skip to content

Commit 40a3487

Browse files
authored
Merge pull request #163 from fiveisprime/master
Update the Azure example to match recent updates.
2 parents d7b1444 + f3c53fa commit 40a3487

File tree

5 files changed

+1179
-21
lines changed

5 files changed

+1179
-21
lines changed

azure-node-simple-http-endpoint/README.md

+19-7
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,40 @@ layout: Doc
55
-->
66
# Simple HTTP example
77

8-
In this example, we deploy an HTTP Node.js Azure Function. This sample show you how to read properties off of a query string or the request body, then set a result back to Azure.
8+
In this example, we deploy an HTTP Node.js Azure Function. This sample show you
9+
how to read properties off of a query string or the request body, then set a
10+
result back to Azure.
911

1012
See the [Azure Functions Serverless Plugin docs](https://www.serverless.com/framework/docs/providers/azure/) for more info.
1113

14+
_Note: you may need to change the `service` name in `serverless.yml`_
15+
1216
## Setup
1317

1418
1. We recommend Node.js v6.5.0
15-
2. Install the serverless framework - `npm i -g serverless`
16-
3. Install the dependencies of this example - `npm i`
19+
2. Install the serverless framework - `npm install -g serverless`
20+
3. Install the dependencies of this example - `npm install`
1721

1822
## Deploying
1923

20-
To deploy, set up your [Credentials](https://www.serverless.com/framework/docs/providers/azure/guide/credentials) and run
24+
To deploy, use the `deploy` and follow the instructions to log into your Azure
25+
account.
2126

2227
```bash
23-
serverless deploy
28+
$ serverless deploy
29+
Serverless: Packaging service...
30+
Serverless: Logging in to Azure
31+
Serverless: Paste this code (copied to your clipboard) into the launched browser, and complete the authentication process: BLAZSRMVJ
2432
```
2533

34+
Once authenticated, the session will continue and deploy the app.
35+
2636
## Invoking
2737

28-
Once deployed, run
38+
Invoke the deployed function using the `invoke` command.
2939

3040
```bash
31-
serverless invoke -f hello
41+
$ serverless invoke -f hello -d "{ \"name\": \"World\" }"
42+
Serverless: Logging in to Azure
43+
"Hello World"
3244
```

azure-node-simple-http-endpoint/handler.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22

33
module.exports.hello = (context, req) => {
44
context.log('JavaScript HTTP trigger function processed a request.');
5+
56
const res = {};
7+
68
if (req.query.name || (req.body && req.body.name)) {
7-
// status: 200, /* Defaults to 200 */
89
const name = req.query.name || req.body.name;
10+
911
res.body = `Hello ${name}`;
1012
} else {
1113
res.status = 400;
1214
res.body = 'Please pass a name on the query string or in the request body';
1315
}
16+
1417
context.done(null, res);
1518
};

azure-node-simple-http-endpoint/package.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@
33
"version": "0.1.0",
44
"description": "An example of making http endpoints with the Azure Functions Serverless Framework plugin",
55
"main": "index.js",
6-
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
8-
},
96
"author": "serverless.com",
107
"license": "MIT",
118
"dependencies": {
12-
"serverless-azure-functions": "^0.1.0"
9+
"serverless-azure-functions": "^0.2.0"
1310
}
1411
}

azure-node-simple-http-endpoint/serverless.yml

+3-9
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ service: azfx-node-http
22

33
provider:
44
name: azure
5-
azureSubId: YourAzureSubscriptionID
6-
azureServicePrincipalTenantId: servicePrincipalTenantId
7-
azureservicePrincipalClientId: servicePrincipalClientId
8-
azureServicePrincipalPassword: servicePrincipalPassword
95
location: West US
106

117
plugins:
@@ -19,11 +15,9 @@ package:
1915
- .git/**
2016

2117
functions:
22-
hello:
18+
hello:
2319
handler: handler.hello
24-
events:
20+
events:
2521
- http: true
2622
x-azure-settings:
27-
authLevel : anonymous
28-
29-
23+
authLevel: anonymous

0 commit comments

Comments
 (0)