1 | # API Deploy
|
2 |
|
3 | API Deploy is a Command Line Tool to publish your API. Currently, AWS Lambda is implemented, with API Gateway on the way. You can also export an SDK to use on the Web or Node (more platforms to come). Your SDK and Lambdas are both built based your project's `deployfile.js`.
|
4 |
|
5 | ## To use API Deploy:
|
6 |
|
7 | First, you'll need to `npm install api-deploy -g`. This gives you a new terminal command: `api`. Now, create a `deployfile.js` in your project:
|
8 |
|
9 | ```
|
10 | var deployer = require('api-deploy').configure({
|
11 | sdk: {
|
12 | name: 'MyAPI',
|
13 | url: 'http://myapi.com'
|
14 | },
|
15 | swagger: {
|
16 | path: './swagger.json'
|
17 | },
|
18 | routes: require('./routes')
|
19 | });
|
20 |
|
21 | var pluginConfig = {
|
22 | lambda: {
|
23 | role: 'arn:aws:iam::xxxxxxxxxx:role/root'
|
24 | },
|
25 | aws: {
|
26 | profile: config.aws.profile,
|
27 | region: 'us-east-1',
|
28 | IdentityPoolId: 'xxxxx'
|
29 | }
|
30 | };
|
31 |
|
32 | require('api-deploy/plugins/local').register(deployer).configure(pluginConfig);
|
33 | require('api-deploy/plugins/lambda').register(deployer).configure(pluginConfig);
|
34 | require('api-deploy/plugins/apigateway').register(deployer).configure(pluginConfig);
|
35 |
|
36 | module.exports = deployer;
|
37 | ```
|
38 |
|
39 | ## Now, you can deploy your API at API Gateway:
|
40 |
|
41 | - `api deploy apigateway` - Deploy your API Gateway to AWS
|
42 | - `api deploy apigateway /accounts /other {operationId}` - Deploy selected API Gateway routes (also deploys child/ancestor routes)
|
43 | - `api deploy apigateway --sdk` - Deploy your API Gateway and generate a connected SDK
|
44 |
|
45 | ## Now, you can deploy your Lambdas with:
|
46 |
|
47 | - `api deploy lambda` - Deploy your Lambdas to AWS
|
48 | - `api deploy lambda /accounts /other {operationId}` - Deploy selected Lambdas (also deploys child/ancestor routes)
|
49 | - `api deploy lambda --sdk` - Deploy your Lambdas and generate a connected SDK
|
50 |
|
51 | ## How can I test my code locally?
|
52 |
|
53 | API Deploy comes with a local hapi server that functions like your API Gateway:
|
54 |
|
55 | - `api deploy local` - Saves a hapi server at `./local.js`
|
56 | - `api deploy local --serve --watch --sdk` - **Test your Lambdas @ http://localhost:8000 and generate a connected SDK!**
|
57 | - `api deploy local -sw --sdk` - A shortform of the above
|
58 |
|
59 | ## You can also generate an SDK:
|
60 |
|
61 | - `api sdk lambda` - Build an SDK that points to your AWS Lambdas (saved at `./sdk-lambda.js`)!
|
62 | - - `api sdk apigateway` - Build an SDK that points to your API Gateway (saved at `./sdk-apigateway.js`)!
|
63 | - `api sdk local` - Build a local server you can run with `node local` (saved at `./sdk-local.js`)!
|
64 | - `api sdk local --prettify` - Build an SDK that is not minified
|
65 |
|
66 | ## Use an SDK by including (via Node or Script tag), then:
|
67 |
|
68 | ```
|
69 | MyAPI.init( new AWS.Lambda() ); // Only required if using the Lambda SDK
|
70 |
|
71 | MyAPI.accountsCreate({
|
72 | headers: {}, // HTTP Headers
|
73 | query: {}, // URL Get Params (eg. /?param=123)
|
74 | params: {}, // Dynamic URL segment params (eg. /accounts/{accountID})
|
75 | payload: {} // eg. POSTed Data
|
76 | }, function(err, data) {
|
77 | console.log('Response from your API:', err, data);
|
78 | });
|
79 | ```
|
80 |
|
81 | ## Want to see an example API?
|
82 |
|
83 | [https://github.com/dallasread/api-deploy/tree/master/example-api](https://github.com/dallasread/api-deploy/tree/master/example-api)
|
84 |
|
85 | # TODO
|
86 | - Undeploy Resources
|