Skip to content

Instantly share code, notes, and snippets.

@brianfoody
Last active February 29, 2020 11:53
Show Gist options
  • Save brianfoody/1b31215ee2aac0dbd93bf9140173661f to your computer and use it in GitHub Desktop.
Save brianfoody/1b31215ee2aac0dbd93bf9140173661f to your computer and use it in GitHub Desktop.
Multi-region serverless application with AWS CDK
import {
RestApi,
CfnAuthorizer,
DomainName,
EndpointType,
CfnBasePathMapping
} from "@aws-cdk/aws-apigateway";
import { Certificate, ValidationMethod } from "@aws-cdk/aws-certificatemanager";
import { Construct } from "@aws-cdk/core";
import {
CfnHealthCheck,
} from "@aws-cdk/aws-route53";
import { LayerVersion } from "@aws-cdk/aws-lambda";
export class RootResources extends Construct {
api: RestApi;
layer: LayerVersion;
authorizer: CfnAuthorizer;
constructor(
parent: Construct,
name: string,
props: {
userPoolArn: string;
region: string;
}
) {
super(parent, name);
// API
this.api = new RestApi(this, "RegionalApi", {
endpointTypes: [EndpointType.REGIONAL]
});
const certificate = new Certificate(this, "ApiCertificate", {
domainName: "api.multi.com",
validationMethod: ValidationMethod.DNS
});
const domain = new DomainName(this, "APIDomain", {
domainName: "api.multi.com",
certificate,
endpointType: EndpointType.REGIONAL
});
new CfnBasePathMapping(this, "Resource", {
basePath: "(none)",
domainName: domain.domainName,
restApiId: this.api.restApiId,
stage: this.api.deploymentStage.stageName
});
new CfnHealthCheck(this, "ApiHealthCheck", {
healthCheckConfig: {
port: 443,
type: "HTTPS",
resourcePath: "/prod/health/check",
fullyQualifiedDomainName: `${this.api.restApiId}.execute-api.${props.region}.amazonaws.com`,
requestInterval: 30,
failureThreshold: 2
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment