-
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
25 changed files
with
5,363 additions
and
459 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: Build & Deploy | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
|
||
concurrency: | ||
group: pr_${{ github.head_ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
build_deploy: | ||
name: Build & Deploy | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Setup Node.js environment | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: "20" | ||
|
||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install dependencies | ||
uses: bahmutov/npm-install@v1 | ||
|
||
- name: Build | ||
run: | | ||
npm run build | ||
npm run deploy | ||
- name: Deploy | ||
env: | ||
AWS_ACCESS_KEY_ID: ${{ secrets.DEPLOY_AWS_ACCESS_KEY_ID }} | ||
AWS_SECRET_ACCESS_KEY: ${{ secrets.DEPLOY_AWS_SECRET_ACCESS_KEY }} | ||
AWS_DEFAULT_REGION: eu-central-1 | ||
run: | | ||
npx cdk deploy --require-approval never |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.vscode | ||
.DS_Store | ||
node_modules/ | ||
cdk.out/ |
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,6 @@ | ||
{ | ||
"hosted-zone:account=511361162520:domainName=rs.school:region=eu-central-1": { | ||
"Id": "/hostedzone/Z060689922CU3BKTLJ3DO", | ||
"Name": "rs.school." | ||
} | ||
} |
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,10 @@ | ||
{ | ||
"app": "npx ts-node src/cdk/App.ts", | ||
"context": { | ||
"@aws-cdk/aws-apigateway:usagePlanKeyOrderInsensitiveId": true, | ||
"@aws-cdk/core:stackRelativeExports": true, | ||
"@aws-cdk/aws-lambda:recognizeVersionProps": true, | ||
"@aws-cdk/aws-cloudfront:defaultSecurityPolicyTLSv1.2_2021": true, | ||
"@aws-cdk/core:target-partitions": ["aws", "aws-cn"] | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,12 +1,21 @@ | ||
{ | ||
"scripts": { | ||
"build": "tsc", | ||
"deploy": "npx cdk deploy --require-approval never", | ||
"format": "prettier --write src" | ||
}, | ||
"dependencies": { | ||
"@aws-cdk/aws-apigatewayv2-alpha": "2.110.0-alpha.0", | ||
"@aws-cdk/aws-apigatewayv2-integrations-alpha": "2.110.0-alpha.0", | ||
"@aws-sdk/client-dynamodb": "^3.458.0", | ||
"aws-cdk-lib": "2.110.1", | ||
"constructs": "^10", | ||
"querystring": "^0.2.1", | ||
"ts-node": "^10.9.1" | ||
}, | ||
"devDependencies": { | ||
"@types/aws-lambda": "^8.10.129", | ||
"esbuild": "^0.19.8", | ||
"prettier": "^3.1.0" | ||
} | ||
} |
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,195 @@ | ||
import * as cdk from "aws-cdk-lib"; | ||
import * as route53 from "aws-cdk-lib/aws-route53"; | ||
import * as alias from "aws-cdk-lib/aws-route53-targets"; | ||
import * as apiv2 from "@aws-cdk/aws-apigatewayv2-alpha"; | ||
import * as integration from "@aws-cdk/aws-apigatewayv2-integrations-alpha"; | ||
|
||
import * as cloudfront from "aws-cdk-lib/aws-cloudfront"; | ||
import { Construct } from "constructs"; | ||
import { CfnOutput } from "aws-cdk-lib"; | ||
import { NodejsFunction } from "aws-cdk-lib/aws-lambda-nodejs"; | ||
import { Runtime } from "aws-cdk-lib/aws-lambda"; | ||
|
||
type Props = cdk.StackProps & { | ||
certificateArn: string; | ||
}; | ||
|
||
export class AngularCourseStack extends cdk.Stack { | ||
fqdn: string; | ||
url: string; | ||
|
||
constructor(scope: Construct, id: string, props: Props) { | ||
super(scope, id, props); | ||
|
||
const { certificateArn } = props; | ||
|
||
this.fqdn = `tasks.app.rs.school`; | ||
this.url = `https://${this.fqdn}`; | ||
|
||
const api: { | ||
path: string; | ||
method: string; | ||
lambdaName: string; | ||
}[] = [ | ||
{ | ||
path: "/login", | ||
method: "POST", | ||
lambdaName: "login", | ||
}, | ||
{ | ||
path: "/logout", | ||
method: "DELETE", | ||
lambdaName: "logout", | ||
}, | ||
{ | ||
path: "/registration", | ||
method: "POST", | ||
lambdaName: "registration", | ||
}, | ||
{ | ||
path: "/users", | ||
method: "GET", | ||
lambdaName: "users", | ||
}, | ||
{ | ||
path: "/profile", | ||
method: "GET", | ||
lambdaName: "profile-read", | ||
}, | ||
{ | ||
path: "/profile", | ||
method: "PUT", | ||
lambdaName: "profile-update", | ||
}, | ||
{ | ||
path: "/conversations/list", | ||
method: "GET", | ||
lambdaName: "list-my-conversations", | ||
}, | ||
{ | ||
path: "/conversations/create", | ||
method: "POST", | ||
lambdaName: "create-personal-conversation", | ||
}, | ||
{ | ||
path: "/conversations/delete", | ||
method: "DELETE", | ||
lambdaName: "delete-personal-conversation", | ||
}, | ||
{ | ||
path: "/conversations/read", | ||
method: "GET", | ||
lambdaName: "conversation-read-messages", | ||
}, | ||
{ | ||
path: "/conversations/append", | ||
method: "POST", | ||
lambdaName: "conversation-add-message", | ||
}, | ||
{ | ||
path: "/groups/list", | ||
method: "GET", | ||
lambdaName: "groups-list", | ||
}, | ||
{ | ||
path: "/groups/create", | ||
method: "POST", | ||
lambdaName: "groups-create", | ||
}, | ||
{ | ||
path: "/groups/delete", | ||
method: "DELETE", | ||
lambdaName: "groups-delete", | ||
}, | ||
{ | ||
path: "/groups/read", | ||
method: "GET", | ||
lambdaName: "groups-read-messages", | ||
}, | ||
{ | ||
path: "/groups/append", | ||
method: "POST", | ||
lambdaName: "groups-add-message", | ||
}, | ||
]; | ||
|
||
const httpApi = new apiv2.HttpApi(this, "HttpApi"); | ||
|
||
for (const route of api) { | ||
new apiv2.HttpRoute(this, `Route-${route.path}-${route.method}`, { | ||
httpApi, | ||
integration: new integration.HttpLambdaIntegration( | ||
`Integration-${route.path}-${route.method}`, | ||
new NodejsFunction(this, `Lambda-${route.lambdaName}`, { | ||
entry: `./src/functions/${route.lambdaName}.ts`, | ||
memorySize: 256, | ||
runtime: Runtime.NODEJS_20_X, | ||
bundling: { | ||
externalModules: ["@aws-sdk/*"], | ||
}, | ||
}), | ||
), | ||
routeKey: apiv2.HttpRouteKey.with("/"), | ||
}); | ||
} | ||
|
||
const noCacheBehavior: cloudfront.Behavior = { | ||
allowedMethods: cloudfront.CloudFrontAllowedMethods.ALL, | ||
defaultTtl: cdk.Duration.seconds(0), | ||
minTtl: cdk.Duration.seconds(0), | ||
maxTtl: cdk.Duration.seconds(0), | ||
forwardedValues: { | ||
queryString: true, | ||
headers: ["Origin", "Authorization"], | ||
cookies: { | ||
forward: "all", | ||
}, | ||
}, | ||
}; | ||
|
||
const distribution = new cloudfront.CloudFrontWebDistribution( | ||
this, | ||
"Tasks", | ||
{ | ||
originConfigs: [ | ||
{ | ||
customOriginSource: { | ||
domainName: httpApi.url!, | ||
originProtocolPolicy: cloudfront.OriginProtocolPolicy.HTTPS_ONLY, | ||
}, | ||
behaviors: [ | ||
{ | ||
isDefaultBehavior: true, | ||
pathPattern: "/angular/*", | ||
...noCacheBehavior, | ||
}, | ||
], | ||
}, | ||
], | ||
defaultRootObject: "/", | ||
viewerCertificate: { | ||
aliases: [this.fqdn], | ||
props: { | ||
// cloudfront needs certificate in us-east-1 so we pass it as string | ||
acmCertificateArn: certificateArn, | ||
sslSupportMethod: "sni-only", | ||
minimumProtocolVersion: "TLSv1.2_2019", | ||
}, | ||
}, | ||
}, | ||
); | ||
|
||
// Create a DNS record. in Production it will be an apex record, otherwise we set recordName | ||
new route53.ARecord(this, "AliasRecord", { | ||
target: route53.RecordTarget.fromAlias( | ||
new alias.CloudFrontTarget(distribution), | ||
), | ||
zone: route53.HostedZone.fromLookup(this, "HostedZone", { | ||
domainName: "rs.school", | ||
}), | ||
recordName: this.fqdn, | ||
}); | ||
|
||
new CfnOutput(this, "Url", { value: this.url }); | ||
} | ||
} |
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,10 @@ | ||
import * as cdk from "aws-cdk-lib"; | ||
import { AngularCourseStack } from "./AngularCourseStack"; | ||
|
||
const app = new cdk.App(); | ||
|
||
new AngularCourseStack(app, `rsschool-tasks`, { | ||
env: { account: "511361162520", region: "eu-central-1" }, | ||
certificateArn: | ||
"arn:aws:acm:us-east-1:511361162520:certificate/07e01035-1bb4-430c-8b82-625565f66bdb", | ||
}); |
Oops, something went wrong.