-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b932c1b
commit dbbac6a
Showing
8 changed files
with
839,962 additions
and
1 deletion.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
source/patterns/@aws-solutions-constructs/aws-route53-apigateway/.eslintignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
lib/*.js | ||
test/*.js | ||
*.d.ts | ||
coverage | ||
test/lambda/index.js |
15 changes: 15 additions & 0 deletions
15
source/patterns/@aws-solutions-constructs/aws-route53-apigateway/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
lib/*.js | ||
test/*.js | ||
*.js.map | ||
*.d.ts | ||
node_modules | ||
*.generated.ts | ||
dist | ||
.jsii | ||
|
||
.LAST_BUILD | ||
.nyc_output | ||
coverage | ||
.nycrc | ||
.LAST_PACKAGE | ||
*.snk |
21 changes: 21 additions & 0 deletions
21
source/patterns/@aws-solutions-constructs/aws-route53-apigateway/.npmignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Exclude typescript source and config | ||
*.ts | ||
tsconfig.json | ||
coverage | ||
.nyc_output | ||
*.tgz | ||
*.snk | ||
*.tsbuildinfo | ||
|
||
# Include javascript files and typescript declarations | ||
!*.js | ||
!*.d.ts | ||
|
||
# Exclude jsii outdir | ||
dist | ||
|
||
# Include .jsii | ||
!.jsii | ||
|
||
# Include .jsii | ||
!.jsii |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
source/patterns/@aws-solutions-constructs/aws-route53-apigateway/lib/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
/** | ||
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance | ||
* with the License. A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES | ||
* OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions | ||
* and limitations under the License. | ||
*/ | ||
|
||
// Imports | ||
import * as api from '@aws-cdk/aws-apigateway'; | ||
import * as route53 from "@aws-cdk/aws-route53"; | ||
import * as targets from '@aws-cdk/aws-route53-targets'; | ||
import * as ec2 from '@aws-cdk/aws-ec2'; | ||
import * as defaults from '@aws-solutions-constructs/core'; | ||
import * as certificatemanager from '@aws-cdk/aws-certificatemanager'; | ||
// Note: To ensure CDKv2 compatibility, keep the import statement for Construct separate | ||
import { Construct } from '@aws-cdk/core'; | ||
|
||
/** | ||
* The properties for the Route53ToApiGateway class. | ||
*/ | ||
export interface Route53ToApiGatewayProps { | ||
/** | ||
* Whether to create a public or private API. This value has implications | ||
* for the VPC, the type of Hosted Zone and the Application Load Balancer | ||
* | ||
* @default - None | ||
*/ | ||
readonly publicApi: boolean | ||
/** | ||
* Custom properties for a new Private Hosted Zone. Cannot be specified for a | ||
* public API. Cannot specify a VPC | ||
* | ||
* @default - None | ||
*/ | ||
readonly privateHostedZoneProps?: route53.PrivateHostedZoneProps | any, | ||
/** | ||
* Existing Public or Private Hosted Zone. If a Private Hosted Zone, must | ||
* exist in the same VPC specified in existingVpc | ||
* | ||
* @default - None | ||
*/ | ||
readonly existingHostedZoneInterface?: route53.IHostedZone, | ||
/** | ||
* An existing VPC. Providing both this and vpcProps is an error. If an existingAlb or existing | ||
* Private Hosted Zone is provided, this value must be the VPC associated with those resources. | ||
* | ||
* @default - None | ||
*/ | ||
readonly existingVpc?: ec2.IVpc, | ||
/** | ||
* The existing API Gateway instance that will be protected with the WAF web ACL. | ||
* | ||
* @default - None | ||
*/ | ||
readonly existingApiGatewayInterface: api.IRestApi, | ||
/** | ||
* An existing AWS Certificate Manager certificate for your custom domain name. | ||
* | ||
* @defualt - None | ||
*/ | ||
readonly existingCertificateInterface?: certificatemanager.ICertificate; | ||
} | ||
|
||
/** | ||
* @summary The Route53ToApiGateway class. | ||
*/ | ||
export class Route53ToApiGateway extends Construct { | ||
public readonly hostedZone: route53.IHostedZone; | ||
public readonly vpc?: ec2.IVpc; | ||
public readonly apiGateway: api.RestApi; | ||
public readonly certificate: certificatemanager.ICertificate; | ||
/** | ||
* @summary Constructs a new instance of the Route53ToApiGateway class. | ||
* @param {cdk.App} scope - represents the scope for all the resources. | ||
* @param {string} id - this is a a scope-unique id. | ||
* @param {Route53ToApiGatewayProps} props - user provided props for the construct | ||
* @since 0.8.0 | ||
* @access public | ||
*/ | ||
constructor(scope: Construct, id: string, props: Route53ToApiGatewayProps) { | ||
super(scope, id); | ||
defaults.CheckProps(props); | ||
|
||
if (props.existingVpc) { | ||
this.vpc = props.existingVpc; | ||
} | ||
|
||
// Existing Public or Private Hosted Zone | ||
if (props.existingHostedZoneInterface) { | ||
this.hostedZone = props.existingHostedZoneInterface; | ||
} else { // Creating a Private Hosted Zone | ||
if (props.publicApi) { | ||
throw new Error('Public APIs require an existingHostedZone be passed in the Props object.'); | ||
} else { | ||
if (!props.privateHostedZoneProps) { | ||
throw new Error('Must supply privateHostedZoneProps to create a private API'); | ||
} | ||
if (props.privateHostedZoneProps.vpc) { | ||
throw new Error('All VPC specs must be provided at the Construct level in Route53ToApiGatewayProps'); | ||
} | ||
const manufacturedProps: route53.PrivateHostedZoneProps = defaults.overrideProps(props.privateHostedZoneProps, { vpc: this.vpc }); | ||
this.hostedZone = new route53.PrivateHostedZone(this, `${id}-zone`, manufacturedProps); | ||
} | ||
} | ||
|
||
// Create certificate and validate CNAME Record with DNS | ||
if (props.existingCertificateInterface) { // Certificate must already be issued if user is bringing an existing one | ||
this.certificate = props.existingCertificateInterface; | ||
} else { | ||
this.certificate = new certificatemanager.Certificate(this, 'Certificate', { | ||
domainName: this.hostedZone.zoneName, | ||
validation: certificatemanager.CertificateValidation.fromDns(this.hostedZone), | ||
}); | ||
} | ||
|
||
// Convert IRestApi to RestApi | ||
this.apiGateway = props.existingApiGatewayInterface as api.RestApi; | ||
|
||
// Add custom domain name in API Gateway | ||
this.apiGateway.addDomainName('CustomDomainName', { | ||
domainName: this.hostedZone.zoneName, | ||
certificate: this.certificate | ||
}); | ||
|
||
// Create A Record in custom domain to route traffic to API Gateway | ||
new route53.ARecord(this, 'CustomDomainAliasRecord', { | ||
zone: this.hostedZone, | ||
target: route53.RecordTarget.fromAlias(new targets.ApiGateway(this.apiGateway)) | ||
}); | ||
} | ||
} |
100 changes: 100 additions & 0 deletions
100
source/patterns/@aws-solutions-constructs/aws-route53-apigateway/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
{ | ||
"name": "@aws-solutions-constructs/aws-route53-apigateway", | ||
"version": "0.0.0", | ||
"description": "CDK constructs for connecting an Amazon Route53 domain to an API Gateway.", | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/awslabs/aws-solutions-constructs.git", | ||
"directory": "source/patterns/@aws-solutions-constructs/aws-route53-apigateway" | ||
}, | ||
"author": { | ||
"name": "Amazon Web Services", | ||
"url": "https://aws.amazon.com", | ||
"organization": true | ||
}, | ||
"license": "Apache-2.0", | ||
"scripts": { | ||
"build": "tsc -b .", | ||
"lint": "eslint -c ../eslintrc.yml --ext=.js,.ts . && tslint --project .", | ||
"lint-fix": "eslint -c ../eslintrc.yml --ext=.js,.ts --fix .", | ||
"test": "jest --coverage", | ||
"clean": "tsc -b --clean", | ||
"watch": "tsc -b -w", | ||
"integ": "cdk-integ", | ||
"integ-no-clean": "cdk-integ --no-clean", | ||
"integ-assert": "cdk-integ-assert", | ||
"jsii": "jsii", | ||
"jsii-pacmak": "jsii-pacmak", | ||
"build+lint+test": "npm run jsii && npm run lint && npm test && npm run integ-assert", | ||
"snapshot-update": "npm run jsii && npm test -- -u && npm run integ-assert" | ||
}, | ||
"jsii": { | ||
"outdir": "dist", | ||
"targets": { | ||
"java": { | ||
"package": "software.amazon.awsconstructs.services.route53apigateway", | ||
"maven": { | ||
"groupId": "software.amazon.awsconstructs", | ||
"artifactId": "route53apigateway" | ||
} | ||
}, | ||
"dotnet": { | ||
"namespace": "Amazon.SolutionsConstructs.AWS.Route53ApiGateway", | ||
"packageId": "Amazon.SolutionsConstructs.AWS.Route53ApiGateway", | ||
"signAssembly": true, | ||
"iconUrl": "https://raw.githubusercontent.com/aws/aws-cdk/master/logo/default-256-dark.png" | ||
}, | ||
"python": { | ||
"distName": "aws-solutions-constructs.aws-route53-apigateway", | ||
"module": "aws_solutions_constructs.aws_route53_apigateway" | ||
} | ||
} | ||
}, | ||
"dependencies": { | ||
"@aws-cdk/aws-ec2": "0.0.0", | ||
"@aws-cdk/aws-apigateway": "0.0.0", | ||
"@aws-cdk/aws-certificatemanager": "0.0.0", | ||
"@aws-cdk/core": "0.0.0", | ||
"@aws-cdk/aws-lambda": "0.0.0", | ||
"@aws-cdk/aws-route53": "0.0.0", | ||
"@aws-cdk/aws-route53-targets": "0.0.0", | ||
"@aws-solutions-constructs/core": "0.0.0", | ||
"constructs": "^3.2.0" | ||
}, | ||
"devDependencies": { | ||
"@aws-cdk/assert": "0.0.0", | ||
"@types/jest": "^26.0.22", | ||
"@types/node": "^10.3.0", | ||
"prettier": "^2.5.1" | ||
}, | ||
"jest": { | ||
"moduleFileExtensions": [ | ||
"js" | ||
], | ||
"coverageReporters": [ | ||
"text", | ||
[ | ||
"lcov", | ||
{ | ||
"projectRoot": "../../../../" | ||
} | ||
] | ||
] | ||
}, | ||
"peerDependencies": { | ||
"@aws-cdk/aws-apigateway": "0.0.0", | ||
"@aws-cdk/core": "0.0.0", | ||
"@aws-solutions-constructs/core": "0.0.0", | ||
"constructs": "^3.2.0" | ||
}, | ||
"keywords": [ | ||
"aws", | ||
"cdk", | ||
"awscdk", | ||
"AWS Solutions Constructs", | ||
"Amazon API Gateway", | ||
"Amazon Route 53" | ||
] | ||
} |
8 changes: 8 additions & 0 deletions
8
source/patterns/@aws-solutions-constructs/aws-route53-apigateway/test/lambda/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
exports.handler = async (event, context) => { | ||
console.log('Received event:', JSON.stringify(event, null, 2)); | ||
return { | ||
statusCode: 200, | ||
headers: { 'Content-Type': 'text/plain' }, | ||
body: `Hello from Lambda! You've hit ${event.path}\n` | ||
}; | ||
}; |
Oops, something went wrong.