deployApiGateway

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 deploy.js. Like "us-east-2".

apiGatewayName String

A constant created in deploy.js, is beekeeper-${PROFILE_NAME}-apigateway

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 deploy.js, is "prod"

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 new APIGatewayClient({ region });

apiGatewayName String

A constant from deploy.js, looks like beekeeper-${PROFILE_NAME}-apigateway

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 new APIGatewayClient({ region })

restApiId String

The string returned from createApiGateway()

resourceParentId String

The id of the root resource returned from getResources();

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 new APIGatewayClient({ region })

restApiId String

The string returned from createApiGateway()

apiGatewayName String

A constant from deploy.js, looks like beekeeper-${PROFILE_NAME}-apigateway

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 APIGatewayClient({ region })

restApiId String

The string returned from createApiGateway()

mainResourceId String

The id of the resource returned from createResource();

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 new APIGatewayClient({ region })

mainResourceId String

The id referring to the "/beekeeper" resource

restApiId String

The string returned from createApiGateway()

lambdaUri String

Something we build that refers to the Lambda we want to trigger, looks like arn:aws:apigateway:${region}:lambda:path/2015-03-31/functions/${preLambdaArn}/invocations;

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 new APIGatewayClient({ region })

mainResourceId String

The id referring to the "/beekeeper" resource

restApiId String

The string returned from createApiGateway()

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 new APIGatewayClient({ region })

mainResourceId String

The id referring to the "/beekeeper" resource

restApiId String

The string returned from createApiGateway()

mainResourceName String

A constant: "beekeeper"