From 5d074fc4fdc69ee1dd8f6551f8a4359d4da6881a Mon Sep 17 00:00:00 2001 From: Errietta Kostala Date: Tue, 19 Feb 2019 20:46:49 +0000 Subject: [PATCH 1/3] Update shared API instructions The instructions for shared APIs would always give me errors such as : ``` The CloudFormation template is invalid: Template error: instance of Fn::GetAtt references undefined resource ApiGatewayRestApi ``` After much googling I found https://forum.serverless.com/t/micro-services-with-shared-api-gateway/6486/2 and the solution proposed (deploying the API and exports as their own service) totally worked for me. I thought to update the instructions so more people don't waste hours. Alternatively, if there's a way of making it work the way mentioned, please advise! --- docs/providers/aws/events/apigateway.md | 56 +++++++++++++++---------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/docs/providers/aws/events/apigateway.md b/docs/providers/aws/events/apigateway.md index 156cc6b76..346205e4c 100644 --- a/docs/providers/aws/events/apigateway.md +++ b/docs/providers/aws/events/apigateway.md @@ -1085,48 +1085,56 @@ 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': apiGateway-restApiId + restApiRootResourceId: + 'Fn::ImportValue': apiGateway-rootResourceId + +functions: + service-a-functions +``` ```yml service: service-b @@ -1137,6 +1145,8 @@ provider: restApiRootResourceId: 'Fn::ImportValue': apiGateway-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). From 5d18c2e537e54369a017e91374ff4536ff5bdb99 Mon Sep 17 00:00:00 2001 From: Errietta Kostala Date: Tue, 19 Feb 2019 20:53:50 +0000 Subject: [PATCH 2/3] Update apigateway.md --- docs/providers/aws/events/apigateway.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/providers/aws/events/apigateway.md b/docs/providers/aws/events/apigateway.md index 346205e4c..46d061b2a 100644 --- a/docs/providers/aws/events/apigateway.md +++ b/docs/providers/aws/events/apigateway.md @@ -1116,7 +1116,7 @@ resources: - MyApiGW - RootResourceId Export: - Name: myApiGateway-rootResourceId + Name: MyApiGateway-rootResourceId ``` This creates API gateway and then exports the `restApiId` and `rootResourceId` values using cloudformation cross stack output. @@ -1128,9 +1128,9 @@ service: service-a provider: apiGateway: restApiId: - 'Fn::ImportValue': apiGateway-restApiId + 'Fn::ImportValue': MyApiGateway-restApiId restApiRootResourceId: - 'Fn::ImportValue': apiGateway-rootResourceId + 'Fn::ImportValue': MyApiGateway-rootResourceId functions: service-a-functions @@ -1141,9 +1141,9 @@ 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 From 8c15f7dba3e40b5a6896e3b8ddc1d524f456ec7e Mon Sep 17 00:00:00 2001 From: Errietta Kostala Date: Tue, 19 Feb 2019 21:03:39 +0000 Subject: [PATCH 3/3] Fix link while i'm here --- docs/providers/aws/events/apigateway.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/providers/aws/events/apigateway.md b/docs/providers/aws/events/apigateway.md index 46d061b2a..e951bff05 100644 --- a/docs/providers/aws/events/apigateway.md +++ b/docs/providers/aws/events/apigateway.md @@ -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)