-
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
1 parent
5d9ccdd
commit 62e5068
Showing
25 changed files
with
661 additions
and
4 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 |
---|---|---|
|
@@ -7,4 +7,9 @@ package-lock.json | |
local.js | ||
assets/pages.js | ||
assets/partials.js | ||
.wrangler | ||
.wrangler | ||
|
||
dist/ | ||
.idea/ | ||
cdk.out/ | ||
.aws-sam/ |
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,47 @@ | ||
module.exports = { | ||
parser: '@typescript-eslint/parser', | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:@typescript-eslint/recommended' | ||
], | ||
parserOptions: { | ||
ecmaVersion: 2020, | ||
sourceType: 'module' | ||
}, | ||
env: { | ||
es6: true, | ||
node: true, | ||
browser: true | ||
}, | ||
// Ignore files within the node_modules directory | ||
ignorePatterns: ['node_modules/**', 'cdk.out/**'], | ||
rules: { | ||
'no-duplicate-case': 'error', | ||
'no-empty': 'error', | ||
'no-extra-semi': 'error', | ||
'no-func-assign': 'error', | ||
'no-irregular-whitespace': 'error', | ||
'no-unreachable': 'error', | ||
curly: 'error', | ||
'dot-notation': 'error', | ||
eqeqeq: 'error', | ||
'no-empty-function': 'error', | ||
'no-multi-spaces': 'error', | ||
'no-mixed-spaces-and-tabs': 'error', | ||
'no-trailing-spaces': 'error', | ||
'default-case': 'error', | ||
'no-fallthrough': 'error', | ||
'no-unused-vars': 'error', | ||
'no-use-before-define': 'error', | ||
'no-redeclare': 'error', | ||
'brace-style': 'error', | ||
indent: ['error', 2], | ||
quotes: ['error', 'single'], | ||
semi: ['error', 'always'], | ||
radix: 'off', | ||
// TypeScript specific rules | ||
'@typescript-eslint/no-unused-vars': 'error', | ||
'@typescript-eslint/no-use-before-define': 'error', | ||
'@typescript-eslint/no-redeclare': 'error' | ||
} | ||
}; |
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,40 @@ | ||
name: Manual Bootstrap CDK | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: '20' | ||
|
||
- name: Install AWS CLI | ||
run: | | ||
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" | ||
unzip awscliv2.zip | ||
sudo ./aws/install | ||
- name: Configure AWS CLI | ||
env: | ||
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
AWS_DEFAULT_REGION: 'us-east-1' # Replace with your preferred AWS region | ||
run: | | ||
aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID | ||
aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY | ||
aws configure set region $AWS_DEFAULT_REGION | ||
echo "access_key: $AWS_ACCESS_KEY_ID" | ||
echo "secret_key: AWS_SECRET_ACCESS_KEY" | ||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Run tests | ||
run: npm run bootstrap |
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: Manual Deploy CDK | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: '20' | ||
|
||
- name: Install AWS CLI | ||
run: | | ||
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" | ||
unzip awscliv2.zip | ||
sudo ./aws/install | ||
- name: Configure AWS CLI | ||
env: | ||
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
AWS_DEFAULT_REGION: 'us-east-1' # Replace with your preferred AWS region | ||
run: | | ||
aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID | ||
aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY | ||
aws configure set region $AWS_DEFAULT_REGION | ||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Run tests | ||
run: npm run deploy |
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,24 @@ | ||
name: Test CDK Stack | ||
|
||
on: | ||
push: | ||
branches: | ||
- '*' | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: '20' | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Run tests | ||
run: npm test |
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 @@ | ||
.env* | ||
node_modules/ | ||
dist/ | ||
local.js | ||
.idea/ | ||
package-lock.json | ||
cdk.out/ | ||
.aws-sam/ |
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 @@ | ||
# Serverless Backend |
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,41 @@ | ||
{ | ||
"app": "npx ts-node --prefer-ts-exts src/index.ts", | ||
"watch": { | ||
"include": [ | ||
"**" | ||
], | ||
"exclude": [ | ||
"README.md", | ||
"cdk*.json", | ||
"**/*.d.ts", | ||
"**/*.js", | ||
"tsconfig.json", | ||
"package*.json", | ||
"yarn.lock", | ||
"node_modules", | ||
"test" | ||
] | ||
}, | ||
"context": { | ||
"appName": "MyAwesomeApp", | ||
"@aws-cdk/aws-apigateway:usagePlanKeyOrderInsensitiveId": true, | ||
"@aws-cdk/core:stackRelativeExports": true, | ||
"@aws-cdk/aws-rds:lowercaseDbIdentifier": true, | ||
"@aws-cdk/aws-lambda:recognizeVersionProps": true, | ||
"@aws-cdk/aws-lambda:recognizeLayerVersion": true, | ||
"@aws-cdk/aws-cloudfront:defaultSecurityPolicyTLSv1.2_2021": true, | ||
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true, | ||
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true, | ||
"@aws-cdk/core:checkSecretUsage": true, | ||
"@aws-cdk/aws-iam:minimizePolicies": true, | ||
"@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true, | ||
"@aws-cdk/core:validateSnapshotRemovalPolicy": true, | ||
"@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true, | ||
"@aws-cdk/aws-s3:createDefaultLoggingPolicy": true, | ||
"@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true, | ||
"@aws-cdk/core:target-partitions": [ | ||
"aws", | ||
"aws-cn" | ||
] | ||
} | ||
} |
Empty file.
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 @@ | ||
module.exports = { | ||
testEnvironment: 'node', | ||
roots: ['<rootDir>/src'], | ||
testMatch: ['**/*.test.ts'], | ||
transform: { | ||
'^.+\\.tsx?$': 'ts-jest' | ||
} | ||
}; |
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,9 @@ | ||
#!/bin/bash | ||
|
||
npm run synth | ||
|
||
## sam.cmd for windows regular sam for linux/mac | ||
sam.cmd build \ | ||
-t ../../cdk.out/SagaStack-Demo.template.json | ||
|
||
sam.cmd local start-api |
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,4 @@ | ||
{ | ||
"Parameters": { | ||
} | ||
} |
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,7 @@ | ||
{ | ||
"departCity": "Milwaukee", | ||
"departTime": "2024-01-01T00:00:00.000Z", | ||
"arriveCity": "Abuja", | ||
"arriveTime": "2024-01-03T00:00:00.000Z", | ||
"requestId": "tripRequest123" | ||
} |
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,16 @@ | ||
## Local Testing of Lambda Functions | ||
``` | ||
sam local invoke StateMachinereserveFlightLambdaHandler77D8E840 -t ./cdk.out/CdkServerlessSagaStack.template.json | ||
``` | ||
|
||
## Local Testing of API | ||
``` | ||
sam local start-api | ||
``` | ||
|
||
[Local Step Functions Testing](https://docs.aws.amazon.com/step-functions/latest/dg/sfn-local-lambda.html) | ||
|
||
[Local SAM Testing](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-cdk-getting-started.html) | ||
|
||
Examples | ||
-`cdk synth && sam local invoke StateMachinereserveFlightLambdaHandler77D8E840 -t ./cdk.out/CdkServerlessSagaStack.template.json --env-vars ./env.json --event ./event.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,9 @@ | ||
#!/bin/bash | ||
|
||
npm run synth | ||
|
||
# sam.cmd for windows regular sam for linux/mac | ||
sam.cmd local invoke StateMachinereserveFlightLambdaHandler77D8E840 \ | ||
-t ../../../cdk.out/SagaStack-Demo.template.json \ | ||
--env-vars ./env.json \ | ||
--event ./event.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 |
---|---|---|
@@ -1,12 +1,43 @@ | ||
{ | ||
"name": "server", | ||
"name": "serverless-data-machine", | ||
"version": "1.0.0", | ||
"bin": { | ||
"index": "src/index.js" | ||
}, | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"build": "tsc", | ||
"bootstrap": "cdk bootstrap", | ||
"deploy": "cdk deploy --all", | ||
"dev": "sh -c './develop.sh'", | ||
"destroy": "cdk destroy --all", | ||
"lint": "eslint **/*.ts", | ||
"lint-fix": "eslint **/*.ts --fix", | ||
"synth": "cdk synth", | ||
"test": "jest", | ||
"watch": "tsc -w" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC" | ||
"license": "ISC", | ||
"dependencies": { | ||
"aws-cdk-lib": "^2.147.2", | ||
"aws-sdk": "^2.1651.0", | ||
"constructs": "^10.3.0", | ||
"source-map-support": "^0.5.21", | ||
"uuid": "^10.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^29.5.12", | ||
"@types/uuid": "^10.0.0", | ||
"@typescript-eslint/eslint-plugin": "^7.15.0", | ||
"@typescript-eslint/parser": "^7.15.0", | ||
"aws-cdk": "^2.147.2", | ||
"eslint": "^8.57.0", | ||
"jest": "^29.7.0", | ||
"ts-jest": "^29.1.5", | ||
"ts-node": "^10.9.2", | ||
"typescript": "^5.5.2" | ||
} | ||
} |
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,50 @@ | ||
import { Construct } from "constructs"; | ||
import * as Apigw from 'aws-cdk-lib/aws-apigateway'; | ||
import { IRestApi } from "aws-cdk-lib/aws-apigateway"; | ||
import { IFunction } from 'aws-cdk-lib/aws-lambda'; | ||
|
||
export const createApiModels = (scope: Construct, api: IRestApi) => { | ||
// For POST, PUT, DELETE Requests | ||
const requestModel = new Apigw.Model(scope, 'RequestModel', { | ||
restApi: api, | ||
schema: { | ||
type: Apigw.JsonSchemaType.OBJECT, | ||
properties: { | ||
name: { type: Apigw.JsonSchemaType.STRING }, | ||
age: { type: Apigw.JsonSchemaType.NUMBER } | ||
}, | ||
required: ['name'] | ||
} | ||
}); | ||
|
||
const responseModel = new Apigw.Model(scope, 'ResponseModel', { | ||
restApi: api, | ||
schema: { | ||
type: Apigw.JsonSchemaType.OBJECT, | ||
properties: { | ||
message: { type: Apigw.JsonSchemaType.STRING }, | ||
status: { type: Apigw.JsonSchemaType.STRING } | ||
} | ||
} | ||
}); | ||
|
||
return { | ||
requestModel, | ||
responseModel | ||
}; | ||
}; | ||
|
||
export const linkBackendApi = (scope: Construct, api: IRestApi, handler: IFunction, responseModel: any) => { | ||
// Create a new resource (API path) | ||
const resource = api.root.addResource('start'); | ||
|
||
// Add a GET method to the resource with lambda integration to the handler function | ||
resource.addMethod('GET', new Apigw.LambdaIntegration(handler), { | ||
methodResponses: [{ | ||
statusCode: '200', | ||
responseModels: { | ||
'application/json': responseModel | ||
} | ||
}] | ||
}); | ||
}; |
Oops, something went wrong.