Merge pull request #5850 from errietta/patch-1

Update shared API instructions
This commit is contained in:
Philipp Muens 2019-02-20 16:17:02 +01:00 committed by GitHub
commit ff8b011039
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -40,7 +40,7 @@ layout: Doc
- [Custom Status Codes](#custom-status-codes)
- [Setting an HTTP Proxy on API Gateway](#setting-an-http-proxy-on-api-gateway)
- [Share API Gateway and API Resources](#share-api-gateway-and-api-resources)
- [Easiest and CI/CD friendly example of using shared API Gateway and API Resources.](#easiest-and-ci-cd-friendly-example-of-using-shared-api-gateway-and-api-resources)
- [Easiest and CI/CD friendly example of using shared API Gateway and API Resources.](#easiest-and-cicd-friendly-example-of-using-shared-api-gateway-and-api-resources)
- [Manually Configuring shared API Gateway](#manually-configuring-shared-api-gateway)
- [Note while using authorizers with shared API Gateway](#note-while-using-authorizers-with-shared-api-gateway)
- [Share Authorizer](#share-authorizer)
@ -1085,58 +1085,68 @@ functions:
### Easiest and CI/CD friendly example of using shared API Gateway and API Resources.
You can define your API Gateway resource in one of the former service and export the `restApiId` and `restApiRootResourceId` using cloudformation cross-stack references.
You can define your API Gateway resource in its own service and export the `restApiId` and `restApiRootResourceId` using cloudformation cross-stack references.
```yml
service: service-a
service: my-api
provider:
name: aws
runtime: nodejs8.10
stage: dev
region: eu-west-2
resources:
Resources:
YourApiGateway:
Type: AWS::ApiGateway::RestApi
MyApiGW:
Type: AWS::ApiGateway::RestApi
Properties:
Name: YourApiGatewayName
Name: MyApiGW
Outputs:
apiGatewayRestApiId:
Value:
Ref: YourApiGateway
Ref: MyApiGW
Export:
Name: apiGateway-restApiId
Name: MyApiGateway-restApiId
apiGatewayRestApiRootResourceId:
Value:
Fn::GetAtt:
- YourApiGateway
- RootResourceId
Export:
Name: apiGateway-rootResourceId
provider:
apiGateway:
restApiId:
Ref: YourApiGateway
restApiResources:
Fn::GetAtt:
- YourApiGateway
- RootResourceId
functions: ......
- MyApiGW
- RootResourceId
Export:
Name: MyApiGateway-rootResourceId
```
This creates API gateway and then exports the `restApiId` and `rootResourceId` values using cloudformation cross stack output.
We will import this and reference in future services.
```yml
service: service-a
provider:
apiGateway:
restApiId:
'Fn::ImportValue': MyApiGateway-restApiId
restApiRootResourceId:
'Fn::ImportValue': MyApiGateway-rootResourceId
functions:
service-a-functions
```
```yml
service: service-b
provider:
apiGateway:
restApiId:
'Fn::ImportValue': apiGateway-restApiId
'Fn::ImportValue': MyApiGateway-restApiId
restApiRootResourceId:
'Fn::ImportValue': apiGateway-rootResourceId
'Fn::ImportValue': MyApiGateway-rootResourceId
functions:
service-b-functions
```
You can use this method to share your API Gateway across services in same region. Read about this limitation [here](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-importvalue.html).