Skip to content

Commit 30460b8

Browse files
committed
Add documentation for Shared API Gateway
1 parent 510225b commit 30460b8

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,40 @@ stepFunctions:
169169
definition:
170170
```
171171

172+
#### [Share API Gateway and API Resources](https://serverless.com/framework/docs/providers/aws/events/apigateway/#share-api-gateway-and-api-resources)
173+
174+
You can share the same API Gateway between multiple projects by referencing its REST API ID and Root Resource ID in serverless.yml as follows:
175+
176+
```yml
177+
service: service-name
178+
provider:
179+
name: aws
180+
apiGateway:
181+
restApiId: xxxxxxxxxx # REST API resource ID. Default is generated by the framework
182+
restApiRootResourceId: xxxxxxxxxx # Root resource, represent as / path
183+
184+
functions:
185+
...
186+
```
187+
If your application has many nested paths, you might also want to break them out into smaller services.
188+
189+
However, Cloudformation will throw an error if we try to generate an existing path resource. To avoid that, we reference the resource ID:
190+
191+
```yml
192+
service: service-a
193+
provider:
194+
apiGateway:
195+
restApiId: xxxxxxxxxx
196+
restApiRootResourceId: xxxxxxxxxx
197+
restApiResources: # List of existing resources that were created in the REST API. This is required or the stack will be conflicted
198+
199+
/posts: xxxxxxxxxx
200+
201+
functions:
202+
...
203+
```
204+
205+
172206
#### Enabling CORS
173207

174208
To set CORS configurations for your HTTP endpoints, simply modify your event configurations as follows:

0 commit comments

Comments
 (0)