Skip to content

Commit 8a19f30

Browse files
committed
init
0 parents  commit 8a19f30

22 files changed

+11754
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
build

@types/aws-lambda-fastify.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare module "aws-lambda-fastify";

cdk/.gitignore

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
*.js
2+
!jest.config.js
3+
*.d.ts
4+
node_modules
5+
6+
# CDK asset staging directory
7+
.cdk.staging
8+
cdk.out
9+
10+
# Parcel build directories
11+
.cache
12+
.build

cdk/.npmignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.ts
2+
!*.d.ts
3+
4+
# CDK asset staging directory
5+
.cdk.staging
6+
cdk.out

cdk/README.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Welcome to your CDK TypeScript project!
2+
3+
This is a blank project for TypeScript development with CDK.
4+
5+
The `cdk.json` file tells the CDK Toolkit how to execute your app.
6+
7+
## Useful commands
8+
9+
* `npm run build` compile typescript to js
10+
* `npm run watch` watch for changes and compile
11+
* `npm run test` perform the jest unit tests
12+
* `cdk deploy` deploy this stack to your default AWS account/region
13+
* `cdk diff` compare deployed stack with current state
14+
* `cdk synth` emits the synthesized CloudFormation template

cdk/bin/cdk.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env node
2+
import 'source-map-support/register';
3+
import * as cdk from '@aws-cdk/core';
4+
import { CdkStack } from '../lib/cdk-stack';
5+
6+
const app = new cdk.App();
7+
new CdkStack(app, 'CdkStack', {
8+
env: {
9+
region: "eu-central-1"
10+
}
11+
});

cdk/cdk.context.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"@aws-cdk/core:enableStackNameDuplicates": "true",
3+
"aws-cdk:enableDiffNoFail": "true"
4+
}

cdk/cdk.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"app": "npx ts-node bin/cdk.ts"
3+
}

cdk/jest.config.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
roots: ['<rootDir>/test'],
3+
testMatch: ['**/*.test.ts'],
4+
transform: {
5+
'^.+\\.tsx?$': 'ts-jest'
6+
}
7+
};

cdk/lib/cdk-stack.ts

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import * as cdk from '@aws-cdk/core';
2+
import * as lambda from '@aws-cdk/aws-lambda';
3+
import * as apigateway from '@aws-cdk/aws-apigateway';
4+
import * as cloudfront from '@aws-cdk/aws-cloudfront';
5+
import * as path from "path";
6+
import { CfnOutput } from '@aws-cdk/core';
7+
8+
export class CdkStack extends cdk.Stack {
9+
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
10+
super(scope, id, props);
11+
12+
// lambda
13+
const fn = new lambda.Function(this, "MyLambda", {
14+
runtime: lambda.Runtime.NODEJS_12_X,
15+
handler: "build/lambda.handler",
16+
code: lambda.Code.fromAsset(path.join(__dirname, "../cdk-api.zip"))
17+
});
18+
19+
// ApiGW
20+
const apigw = new apigateway.LambdaRestApi(this, "MyApi", {
21+
handler: fn,
22+
proxy: true
23+
});
24+
25+
// CF
26+
const feCf = new cloudfront.CloudFrontWebDistribution(this, "MyCf", {
27+
defaultRootObject: "/",
28+
originConfigs: [{
29+
customOriginSource: {
30+
domainName: `${apigw.restApiId}.execute-api.${this.region}.${this.urlSuffix}`,
31+
},
32+
originPath: '/' + apigw.deploymentStage.stageName,
33+
behaviors: [{
34+
isDefaultBehavior: true,
35+
}]
36+
}],
37+
enableIpV6: true,
38+
});
39+
40+
new CfnOutput(this, "myOut", {
41+
value: feCf.domainName
42+
})
43+
}
44+
}

0 commit comments

Comments
 (0)