You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -19,13 +20,14 @@ This sample uses the [Serverless Application Framework](https://serverless.com/)
19
20
20
21
- Full [TypeScript](https://www.typescriptlang.org/) codebase with strict type annotation - _get as many compile time errors as possible._
21
22
- Deployment to AWS from the command line with [Serverless](https://serverless.com/) - _just run an npm script._
23
+
- Publishing to your custom [Route53](https://aws.amazon.com/route53/) domain name - _for API URLs that live forever._
22
24
- Automated builds with [Travis CI](https://travis-ci.org/) - _get early feedback for every change_.
23
25
- Offline execution - _call your endpoints without deploying them to AWS._
24
26
- Minimal IAM policy to follow the principle of least privilege - _because with great power comes great responsibility_.
25
27
- Code analysis with [TSLint](https://palantir.github.io/tslint/) - _avoid dumb coding mistakes._
26
28
- Unit testing with [Mocha](https://mochajs.org/), mocking with [ts-mockito](https://github.com/NagRock/ts-mockito) - _be free to change your implementation._
27
29
- Test coverage report with [Istanbul](https://istanbul.js.org/) and [Coveralls](https://coveralls.io) - _so you know your weak spots._
28
-
- Generated [Swagger](https://swagger.io/) documentation for the endpoints - _the expected description of your API._
30
+
- Generated [Swagger](https://swagger.io/) documentation for the endpoints, which works well with [SwaggerHub](https://app.swaggerhub.com) - _the expected description of your API._
29
31
- Multiple layers in the code to separate concerns and independently test them - _avoid monolith and complexity._
30
32
- Dependency checks with [David](https://david-dm.org/) and [BitHound](https://www.bithound.io/) - _because the majority of your app is not your code._
31
33
- Sample CRUD implementation (in progress) - _to see it all in action_.
@@ -75,9 +77,22 @@ npm install
75
77
6.**Customize the name of your service** by changing the following line in the `serverless.yml` file:
76
78
77
79
```
78
-
service: serverless-lambda-typescript-example
80
+
service: serverless-sample
79
81
```
80
82
83
+
7.**Customize the name of your domain** by changing the following lines in the `serverless.yml` file:
84
+
85
+
```
86
+
custom:
87
+
customDomain:
88
+
domainName: serverless-sample.balassy.me
89
+
certificateName: serverless-sample.balassy.me
90
+
```
91
+
92
+
**NOTE:** You must have the certificate created in [AWS Certificate Manager](https://aws.amazon.com/certificate-manager/) before executing this command. According to AWS to use an ACM certificate with API Gateway, you must [request or import the certificate](https://serverless.com/blog/serverless-api-gateway-domain/) in the US East (N. Virginia) region.
93
+
94
+
If you don't want to publish your API to a custom domain, remove the `serverless-domain-manager` from the `plugins` section, and the `customDomains` entry from the `custom` section of the `serverless.yml` file.
95
+
81
96
## What you can find in the code
82
97
83
98
### Example CRUD endpoints
@@ -102,6 +117,8 @@ To understand the code, open `src/cities/cities.ts`, find the `getCity` function
102
117
103
118
The `src/swagger` folder contains the `/swagger.json` endpoint which exports the documentation of the API in [Swagger](https://swagger.io/) format. Call the endpoint after deploying your API and paste the response JSON into the [Swagger Editor](https://editor.swagger.io) to display it in a friendly way.
104
119
120
+
You can also reference the `swagger.json` URL when you publish your documentation via [SwaggerHub](https://app.swaggerhub.com), as you can see on the SwaggerHub page of this sample: https://app.swaggerhub.com/apis/balassy/serverless-sample.
121
+
105
122
## Developer tasks
106
123
107
124
### Test the service locally
@@ -124,6 +141,14 @@ You can modify your code after running this command, Serverless will automatical
124
141
125
142
### Deploy to AWS
126
143
144
+
**To create a custom domain for your service in AWS, run this command once:**_This command requires Administrator privileges on Windows!_
145
+
146
+
```bash
147
+
npm run deploy:init
148
+
```
149
+
150
+
According to AWS, after this command it may take up to 40 minutes to initialize the domain with a CloudFront distribution. In practice it usually takes about 10 minutes.
151
+
127
152
**To deploy the service to AWS, run:**_This command requires Administrator privileges on Windows!_
128
153
129
154
```bash
@@ -138,6 +163,12 @@ npm run deploy
138
163
139
164
Verify that the deployment is completed successfully by opening the URL displayed in your console window in your browser. To see all resources created in AWS navigate to CloudFormation in the AWS Console and look for the stack named with the name of your service you specified in Step 6.
140
165
166
+
**To download the Swagger description** of your service, open the following URL in your browser:
0 commit comments