Skip to content

Commit e3d3845

Browse files
committed
Add quiz backend
0 parents  commit e3d3845

23 files changed

+12571
-0
lines changed

Diff for: .dockerignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
app/cdk.out
2+
node_modules

Diff for: .gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules/
2+
.DS_Store
3+
config.json
4+
dist
5+
cdk.out
6+
content.json

Diff for: Dockerfile

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
FROM alpine:latest
2+
3+
RUN apk update && apk add bash
4+
5+
RUN apk add --no-cache \
6+
python3 \
7+
py3-pip \
8+
&& pip3 install --upgrade pip \
9+
&& pip3 install --no-cache-dir \
10+
awscli \
11+
&& rm -rf /var/cache/apk/*
12+
13+
RUN apk add nodejs npm
14+
RUN apk add jq
15+
16+
RUN adduser -S worker
17+
RUN mkdir -p /home/worker
18+
19+
WORKDIR /home/worker
20+
COPY start.sh /home/worker/start.sh
21+
COPY functions.sh /home/worker/functions.sh
22+
COPY bootstrap.sh /home/worker/bootstrap.sh
23+
ADD app /home/worker/app
24+
ADD lambda /home/worker/lambda
25+
RUN chown -R worker /home/worker/*
26+
USER worker
27+
28+
RUN /bin/bash bootstrap.sh
29+
30+
ENTRYPOINT /bin/bash start.sh

Diff for: README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# aws-bid
2+
3+
Is a secret project, if you need to know what's going on here, you will know.

Diff for: app/.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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+
src/dist

Diff for: app/.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

Diff for: app/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

Diff for: app/bin/app.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 { App } from '@aws-cdk/core';
4+
import { AppStack } from '../lib/app-stack';
5+
6+
const app = new App();
7+
new AppStack(app, `exxeta-aws-quiz${process.env.QUIZ_SUFFIX || ''}`, {
8+
env: {
9+
region: 'eu-central-1',
10+
},
11+
});

Diff for: app/cdk.json

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"app": "npx ts-node --prefer-ts-exts bin/app.ts",
3+
"watch": {
4+
"include": [
5+
"**"
6+
],
7+
"exclude": [
8+
"README.md",
9+
"cdk*.json",
10+
"**/*.d.ts",
11+
"**/*.js",
12+
"tsconfig.json",
13+
"package*.json",
14+
"yarn.lock",
15+
"node_modules",
16+
"test"
17+
]
18+
},
19+
"context": {
20+
"@aws-cdk/aws-apigateway:usagePlanKeyOrderInsensitiveId": true,
21+
"@aws-cdk/core:stackRelativeExports": true,
22+
"@aws-cdk/aws-rds:lowercaseDbIdentifier": true,
23+
"@aws-cdk/aws-lambda:recognizeVersionProps": true,
24+
"@aws-cdk/aws-cloudfront:defaultSecurityPolicyTLSv1.2_2021": true,
25+
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
26+
"@aws-cdk/core:target-partitions": [
27+
"aws",
28+
"aws-cn"
29+
]
30+
}
31+
}

Diff for: app/jest.config.js

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

Diff for: app/lib/app-stack.ts

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { CorsHttpMethod, HttpApi, HttpMethod } from '@aws-cdk/aws-apigatewayv2';
2+
import { HttpLambdaIntegration } from '@aws-cdk/aws-apigatewayv2-integrations';
3+
import { Runtime, Function, Code, AssetCode } from '@aws-cdk/aws-lambda';
4+
import { Bucket } from '@aws-cdk/aws-s3';
5+
import { BucketDeployment, Source } from '@aws-cdk/aws-s3-deployment';
6+
import { Construct, Stack, StackProps, RemovalPolicy, CfnOutput } from '@aws-cdk/core';
7+
import * as path from 'path';
8+
9+
export class AppStack extends Stack {
10+
constructor(scope: Construct, id: string, props?: StackProps) {
11+
super(scope, id, props);
12+
13+
14+
const deProxyFunction = new Function(this, 'exxeta-deproxy-function', {
15+
runtime: Runtime.NODEJS_14_X,
16+
code: new AssetCode('../lambda/dist'),
17+
handler: 'handler.handler',
18+
environment: {
19+
API_ENDPOINT: `https://nexus.exxeta.info/repository/exxeta-raw-group/exxeta/aws-bids/${process.env.QUIZ_USERNAME || ''}/${process.env.QUIZ_FILE_DE}.json`,
20+
API_USER: process.env.QUIZ_USERNAME || '',
21+
API_PASSWORD: process.env.QUIZ_PASSWORD || '',
22+
}
23+
});
24+
const enProxyFunction = new Function(this, 'exxeta-enproxy-function', {
25+
runtime: Runtime.NODEJS_14_X,
26+
code: new AssetCode('../lambda/dist'),
27+
handler: 'handler.handler',
28+
environment: {
29+
API_ENDPOINT: `https://nexus.exxeta.info/repository/exxeta-raw-group/exxeta/aws-bids/${process.env.QUIZ_USERNAME || ''}/${process.env.QUIZ_FILE_EN}.json`,
30+
API_USER: process.env.QUIZ_USERNAME || '',
31+
API_PASSWORD: process.env.QUIZ_PASSWORD || '',
32+
}
33+
});
34+
35+
const apiGateway = new HttpApi(this, 'exxeta-api');
36+
37+
const deLambdaIntegration = new HttpLambdaIntegration('exxeta-deproxy-integration', deProxyFunction);
38+
const enLambdaIntegration = new HttpLambdaIntegration('exxeta-enproxy-integration', enProxyFunction);
39+
40+
apiGateway.addRoutes({
41+
integration: deLambdaIntegration,
42+
path: '/de',
43+
methods: [HttpMethod.GET],
44+
});
45+
46+
apiGateway.addRoutes({
47+
integration: enLambdaIntegration,
48+
path: '/en',
49+
methods: [HttpMethod.GET],
50+
});
51+
52+
new CfnOutput(this, `api-gw-endpoint`, {
53+
exportName: `exxeta-aws-quiz${process.env.QUIZ_SUFFIX || ''}-endpoint`,
54+
value: apiGateway.apiEndpoint,
55+
});
56+
}
57+
}

0 commit comments

Comments
 (0)