Exports an async function that deploys our REST API Gateway, as opposed to HTTP API Gateway (AWS distinctions). We add one subresource, "/beekeeper" and customize it to handle GET requests. The "/beekeeper" resource handles first time visitors. We have more resources to create but separate those concerns into other modules.
- Source:
(require("deployApiGateway"))(region, apiGatewayName, preLambdaArn, stageName) → {Object}
- Source:
Exports deployApiGateway()
.
Parameters:
Name | Type | Description |
---|---|---|
region |
String | A constant destructured from the CLI user's answers in |
apiGatewayName |
String | A constant created in |
preLambdaArn |
String | Amazon resource name of the Lambda we need the "/beekeeper" resource of this API Gateway to trigger. |
stageName |
String | A constant initialized in |
Returns:
An object with two properties, the restApiId refers to the API Gateway and the stageBeekeeperUrl. The restApiId is needed by other modules to add additional resources. The stageBeekeeperUrl is the URL we build and give to our user: this is the URL they will send out to their users and which redirects to the waiting room.
- Type
- Object
Methods
(async, inner) createApiGateway(apiGateway, apiGatewayName) → {String}
- Source:
Creates the API Gateway and the root "/" resource. The first step of deploying an API Gateway, before you can add resources and methods to it, is to create the API Gateway itself.
Parameters:
Name | Type | Description |
---|---|---|
apiGateway |
APIGatewayClient | Looks like |
apiGatewayName |
String | A constant from |
Returns:
A restApiId used to refer to the API Gateway.
- Type
- String
(async, inner) createResource(apiGateway, restApiId, resourceParentId, mainResourceName) → {String}
- Source:
Creates a subresource "/beekeeper" of root
Parameters:
Name | Type | Description |
---|---|---|
apiGateway |
APIGatewayClient | Looks like |
restApiId |
String | The string returned from |
resourceParentId |
String | The id of the root resource returned from |
mainResourceName |
String | A constant: "beekeeper" |
Returns:
A resourceId referring to this new resource
- Type
- String
(async, inner) getResources(apiGateway, restApiId, apiGatewayName) → {String}
- Source:
Now we query AWS for the id of the root resource "/"
on the API Gateway we previously created. We need this because we need to add further subresources to it.
Parameters:
Name | Type | Description |
---|---|---|
apiGateway |
APIGatewayClient | Looks like |
restApiId |
String | The string returned from |
apiGatewayName |
String | A constant from deploy.js, looks like |
Returns:
An id which refers to the root resource of the API Gateway, i.e. "/"
- Type
- String
(async, inner) mainPutMethodRequest(apiGateway, restApiId, mainResourceId, mainResourceName)
- Source:
Our "/beekeeper" endpoint has one method it handles, a GET request. This function creates it.
Parameters:
Name | Type | Description |
---|---|---|
apiGateway |
APIGatewayClient | Looks like new |
restApiId |
String | The string returned from |
mainResourceId |
String | The id of the resource returned from |
mainResourceName |
String | A constant: "beekeeper" |
(async, inner) setIntegrationRequest(apiGateway, mainResourceId, restApiId, lambdaUri, mainResourceName)
- Source:
Crates and customizes the Integration Request stage. For us, that means triggering a Lambda and setting this stage as "AWS_PROXY", which means the incoming request will be forwarded in its entirety to the Lambda.
Parameters:
Name | Type | Description |
---|---|---|
apiGateway |
APIGatewayClient | Looks like |
mainResourceId |
String | The id referring to the "/beekeeper" resource |
restApiId |
String | The string returned from |
lambdaUri |
String | Something we build that refers to the Lambda we want to trigger, looks like |
mainResourceName |
String | A constant: "beekeeper" |
(async, inner) setIntegrationResponse(apiGateway, mainResourceId, restApiId, mainResourceName)
- Source:
Creates the Integration Response stage. Since the prior stage, the Integration Request stage, specified this process to be AWS_PROXY, there is nothing to customize at this Integration Response stage, just set it up. I.e. the response from the Lambda will be passed through in its entirety.
Parameters:
Name | Type | Description |
---|---|---|
apiGateway |
APIGatewayClient | Looks like |
mainResourceId |
String | The id referring to the "/beekeeper" resource |
restApiId |
String | The string returned from |
mainResourceName |
String | A constant: "beekeeper" |
(async, inner) setMethodResponse(apiGateway, mainResourceId, restApiId, mainResourceName)
- Source:
Creates the Method Response stage. Nothing special is customized in our case. The entire response from the Lambda is forwarded to the client as the API Gateway's response to the original request.
Parameters:
Name | Type | Description |
---|---|---|
apiGateway |
APIGatewayClient | Looks like |
mainResourceId |
String | The id referring to the "/beekeeper" resource |
restApiId |
String | The string returned from |
mainResourceName |
String | A constant: "beekeeper" |