-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
12 changed files
with
8,589 additions
and
15,646 deletions.
There are no files selected for viewing
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
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
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
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,17 @@ | ||
{ | ||
"app": "npx ts-node --project cdk/tsconfig.json --prefer-ts-exts cdk/app.ts", | ||
"context": { | ||
"@aws-cdk/aws-apigateway:usagePlanKeyOrderInsensitiveId": true, | ||
"@aws-cdk/core:enableStackNameDuplicates": "true", | ||
"aws-cdk:enableDiffNoFail": "true", | ||
"@aws-cdk/core:stackRelativeExports": "true", | ||
"@aws-cdk/aws-ecr-assets:dockerIgnoreSupport": true, | ||
"@aws-cdk/aws-secretsmanager:parseOwnedSecretName": true, | ||
"@aws-cdk/aws-kms:defaultKeyPolicies": true, | ||
"@aws-cdk/aws-s3:grantWriteWithoutAcl": true, | ||
"@aws-cdk/aws-ecs-patterns:removeDefaultDesiredCount": true, | ||
"@aws-cdk/aws-rds:lowercaseDbIdentifier": true, | ||
"@aws-cdk/aws-efs:defaultEncryptionAtRest": true, | ||
"@aws-cdk/aws-lambda:recognizeVersionProps": true | ||
} | ||
} |
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,176 @@ | ||
import { AddRoutesOptions, HttpApi, HttpMethod } from '@aws-cdk/aws-apigatewayv2'; | ||
import { HttpLambdaAuthorizer } from "@aws-cdk/aws-apigatewayv2-authorizers"; | ||
import { LambdaProxyIntegration, LambdaProxyIntegrationProps } from '@aws-cdk/aws-apigatewayv2-integrations'; | ||
import { GoFunction, GoFunctionProps } from '@aws-cdk/aws-lambda-go'; | ||
import * as cdk from '@aws-cdk/core'; | ||
import { CfnOutput } from '@aws-cdk/core'; | ||
|
||
type AddOperationOptions = { | ||
name: string; | ||
description?: string; | ||
function: GoFunctionProps; | ||
routes: RouteOptions; | ||
integration?: Omit<LambdaProxyIntegrationProps, 'handler'>; | ||
}; | ||
|
||
type RouteOptions = Omit<AddRoutesOptions, 'integration'>; | ||
type DefaultRouteOptions = Omit<AddRoutesOptions, 'path' | 'methods'>; | ||
|
||
export class Api extends cdk.Construct { | ||
api: HttpApi; | ||
defaultFunctionProps?: GoFunctionProps; | ||
defaultRouteOptions?: DefaultRouteOptions; | ||
|
||
constructor(scope: cdk.Construct, id: string) { | ||
super(scope, id); | ||
|
||
this.api = new HttpApi(this, "ApiGateway"); | ||
|
||
new CfnOutput(this, 'ApiGatewayUrl', { | ||
value: this.api.url!, | ||
}); | ||
} | ||
|
||
setDefaultFunctionProps(props: GoFunctionProps) { | ||
this.defaultFunctionProps = props; | ||
} | ||
|
||
setDefaultRouteOptions(options: DefaultRouteOptions) { | ||
this.defaultRouteOptions = options; | ||
} | ||
|
||
addOperation(opts: AddOperationOptions) { | ||
const { name } = opts; | ||
const functionProps = { | ||
...this.defaultFunctionProps, | ||
...(opts.function || {}), | ||
bundling: { | ||
...(this.defaultFunctionProps?.bundling || {}), | ||
...(opts.function.bundling || {}), | ||
environment: { | ||
...(this.defaultFunctionProps?.bundling?.environment || {}), | ||
...(opts.function.bundling?.environment || {}), | ||
}, | ||
}, | ||
}; | ||
|
||
const lambdaFunction = new GoFunction(this, `${name}Function`, functionProps); | ||
|
||
const routes = this.api.addRoutes({ | ||
...(this.defaultRouteOptions || {}), | ||
...opts.routes, | ||
integration: new LambdaProxyIntegration({ | ||
handler: lambdaFunction, | ||
...opts.integration, | ||
}), | ||
}); | ||
|
||
new CfnOutput(this, `${name}FunctionName`, { | ||
value: lambdaFunction.functionName, | ||
description: `${name} function name`, | ||
}); | ||
|
||
new CfnOutput(this, `${name}ApiPath`, { | ||
value: routes[0].path!, | ||
description: `${name} API path`, | ||
}); | ||
|
||
return { | ||
lambdaFunction, | ||
routes, | ||
}; | ||
} | ||
} | ||
|
||
export class ApiStack extends cdk.Stack { | ||
constructor(scope: cdk.Construct, id: string, properties?: cdk.StackProps) { | ||
super(scope, id, properties); | ||
|
||
const authorizer = new HttpLambdaAuthorizer({ | ||
authorizerName: "UserAuthorizer", | ||
handler: new GoFunction(this, `UserAuthorizerFunction`, { | ||
entry: "lambda/authorizer" | ||
}), | ||
}); | ||
|
||
const api = new Api(this, "Api"); | ||
|
||
api.addOperation({ | ||
name: 'runDatabaseMigrations', | ||
description: 'Run database migrations', | ||
routes: { | ||
path: '/commands/runDatabaseMigrations', | ||
methods: [HttpMethod.POST], | ||
authorizer, | ||
}, | ||
function: { | ||
entry: 'lambda/commands/runDatabaseMigrations', | ||
}, | ||
}); | ||
|
||
api.addOperation({ | ||
name: 'searchLeagues', | ||
description: 'Search leagues', | ||
routes: { | ||
path: '/admin/leagues', | ||
methods: [HttpMethod.GET], | ||
authorizer, | ||
}, | ||
function: { | ||
entry: 'lambda/queries/leagues/search', | ||
}, | ||
}); | ||
|
||
api.addOperation({ | ||
name: 'getLeagueById', | ||
description: 'Get league by ID', | ||
routes: { | ||
path: '/admin/league/{leagueId}', | ||
methods: [HttpMethod.GET], | ||
authorizer: authorizer, | ||
}, | ||
function: { | ||
entry: 'lambda/queries/leagues/search', | ||
}, | ||
}); | ||
|
||
api.addOperation({ | ||
name: 'createLeague', | ||
description: 'Create league', | ||
routes: { | ||
path: '/commands/createLeague', | ||
methods: [HttpMethod.POST], | ||
authorizer: authorizer, | ||
}, | ||
function: { | ||
entry: 'lambda/commands/createLeague', | ||
}, | ||
}); | ||
|
||
api.addOperation({ | ||
name: 'deleteLeague', | ||
description: 'Delete league', | ||
routes: { | ||
path: '/commands/deleteLeague', | ||
methods: [HttpMethod.POST], | ||
authorizer: authorizer, | ||
}, | ||
function: { | ||
entry: 'lambda/commands/deleteLeague', | ||
}, | ||
}); | ||
|
||
api.addOperation({ | ||
name: 'updateLeague', | ||
description: 'Update league', | ||
routes: { | ||
path: '/commands/udpateLeague', | ||
methods: [HttpMethod.POST], | ||
authorizer: authorizer, | ||
}, | ||
function: { | ||
entry: 'lambda/commands/updateLeague', | ||
}, | ||
}); | ||
} | ||
} |
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,31 @@ | ||
#!/usr/bin/env node | ||
|
||
import "source-map-support/register"; | ||
import * as cdk from "@aws-cdk/core"; | ||
import { ApiStack } from "./api.stack"; | ||
|
||
type GolangServerlessCDKTemplateProperties = { | ||
account: string; | ||
}; | ||
|
||
class GolangServerlessCDKTemplate extends cdk.Construct { | ||
constructor( | ||
scope: cdk.Construct, | ||
id: string, | ||
properties: GolangServerlessCDKTemplateProperties | ||
) { | ||
super(scope, id); | ||
new ApiStack(this, `GolangServerlessCDKTemplate`, { | ||
env: { | ||
account: properties.account, | ||
region: "ap-southeast-2", | ||
}, | ||
}); | ||
} | ||
} | ||
|
||
const app = new cdk.App(); | ||
|
||
new GolangServerlessCDKTemplate(app, "Dev", { | ||
account: "067289113644", | ||
}); |
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,30 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2018", | ||
"module": "commonjs", | ||
"lib": [ | ||
"es2018" | ||
], | ||
"declaration": true, | ||
"strict": true, | ||
"noImplicitAny": true, | ||
"strictNullChecks": true, | ||
"noImplicitThis": true, | ||
"alwaysStrict": true, | ||
"noUnusedLocals": false, | ||
"noUnusedParameters": false, | ||
"noImplicitReturns": true, | ||
"noFallthroughCasesInSwitch": false, | ||
"inlineSourceMap": true, | ||
"inlineSources": true, | ||
"experimentalDecorators": true, | ||
"strictPropertyInitialization": false, | ||
"typeRoots": [ | ||
"../node_modules/@types" | ||
] | ||
}, | ||
"exclude": [ | ||
"../node_modules", | ||
"../cdk.out" | ||
] | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.