Skip to content

Commit f23e00c

Browse files
committed
feat: bot boiletplate using AWS SAM, it will interact with IncrementalNGEmitoor
1 parent ae959e1 commit f23e00c

File tree

20 files changed

+2318
-374
lines changed

20 files changed

+2318
-374
lines changed

bots/.eslintrc.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"root": true,
3+
"parser": "@typescript-eslint/parser",
4+
"plugins": ["@typescript-eslint"],
5+
"extends": [
6+
"plugin:@typescript-eslint/recommended",
7+
"prettier",
8+
"prettier/@typescript-eslint"
9+
]
10+
}

bots/.gitignore

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
.esbuild
2+
3+
# Created by https://www.toptal.com/developers/gitignore/api/osx,node,linux,windows,sam
4+
# Edit at https://www.toptal.com/developers/gitignore?templates=osx,node,linux,windows,sam
5+
6+
### Linux ###
7+
*~
8+
9+
# temporary files which can be created if a process still has a handle open of a deleted file
10+
.fuse_hidden*
11+
12+
# KDE directory preferences
13+
.directory
14+
15+
# Linux trash folder which might appear on any partition or disk
16+
.Trash-*
17+
18+
# .nfs files are created when an open file is removed but is still being accessed
19+
.nfs*
20+
21+
### Node ###
22+
# Logs
23+
logs
24+
*.log
25+
npm-debug.log*
26+
yarn-debug.log*
27+
yarn-error.log*
28+
lerna-debug.log*
29+
30+
# Diagnostic reports (https://nodejs.org/api/report.html)
31+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
32+
33+
# Runtime data
34+
pids
35+
*.pid
36+
*.seed
37+
*.pid.lock
38+
39+
# Directory for instrumented libs generated by jscoverage/JSCover
40+
lib-cov
41+
42+
# Coverage directory used by tools like istanbul
43+
coverage
44+
*.lcov
45+
46+
# nyc test coverage
47+
.nyc_output
48+
49+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
50+
.grunt
51+
52+
# Bower dependency directory (https://bower.io/)
53+
bower_components
54+
55+
# node-waf configuration
56+
.lock-wscript
57+
58+
# Compiled binary addons (https://nodejs.org/api/addons.html)
59+
build/Release
60+
61+
# Dependency directories
62+
node_modules/
63+
jspm_packages/
64+
65+
# TypeScript v1 declaration files
66+
typings/
67+
68+
# TypeScript cache
69+
*.tsbuildinfo
70+
71+
# Optional npm cache directory
72+
.npm
73+
74+
# Optional eslint cache
75+
.eslintcache
76+
77+
# Optional stylelint cache
78+
.stylelintcache
79+
80+
# Microbundle cache
81+
.rpt2_cache/
82+
.rts2_cache_cjs/
83+
.rts2_cache_es/
84+
.rts2_cache_umd/
85+
86+
# Optional REPL history
87+
.node_repl_history
88+
89+
# Output of 'npm pack'
90+
*.tgz
91+
92+
# Yarn Integrity file
93+
.yarn-integrity
94+
95+
# dotenv environment variables file
96+
.env
97+
.env.test
98+
.env*.local
99+
100+
# parcel-bundler cache (https://parceljs.org/)
101+
.cache
102+
.parcel-cache
103+
104+
# Next.js build output
105+
.next
106+
107+
# Nuxt.js build / generate output
108+
.nuxt
109+
dist
110+
111+
# Storybook build outputs
112+
.out
113+
.storybook-out
114+
storybook-static
115+
116+
# rollup.js default build output
117+
dist/
118+
119+
# Gatsby files
120+
.cache/
121+
# Comment in the public line in if your project uses Gatsby and not Next.js
122+
# https://nextjs.org/blog/next-9-1#public-directory-support
123+
# public
124+
125+
# vuepress build output
126+
.vuepress/dist
127+
128+
# Serverless directories
129+
.serverless/
130+
131+
# FuseBox cache
132+
.fusebox/
133+
134+
# DynamoDB Local files
135+
.dynamodb/
136+
137+
# TernJS port file
138+
.tern-port
139+
140+
# Stores VSCode versions used for testing VSCode extensions
141+
.vscode-test
142+
143+
# Temporary folders
144+
tmp/
145+
temp/
146+
147+
### OSX ###
148+
# General
149+
.DS_Store
150+
.AppleDouble
151+
.LSOverride
152+
153+
# Icon must end with two \r
154+
Icon
155+
156+
157+
# Thumbnails
158+
._*
159+
160+
# Files that might appear in the root of a volume
161+
.DocumentRevisions-V100
162+
.fseventsd
163+
.Spotlight-V100
164+
.TemporaryItems
165+
.Trashes
166+
.VolumeIcon.icns
167+
.com.apple.timemachine.donotpresent
168+
169+
# Directories potentially created on remote AFP share
170+
.AppleDB
171+
.AppleDesktop
172+
Network Trash Folder
173+
Temporary Items
174+
.apdisk
175+
176+
### SAM ###
177+
# Ignore build directories for the AWS Serverless Application Model (SAM)
178+
# Info: https://aws.amazon.com/serverless/sam/
179+
# Docs: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-reference.html
180+
181+
**/.aws-sam
182+
183+
### Windows ###
184+
# Windows thumbnail cache files
185+
Thumbs.db
186+
Thumbs.db:encryptable
187+
ehthumbs.db
188+
ehthumbs_vista.db
189+
190+
# Dump file
191+
*.stackdump
192+
193+
# Folder config file
194+
[Dd]esktop.ini
195+
196+
# Recycle Bin used on file shares
197+
$RECYCLE.BIN/
198+
199+
# Windows Installer files
200+
*.cab
201+
*.msi
202+
*.msix
203+
*.msm
204+
*.msp
205+
206+
# Windows shortcuts
207+
*.lnk
208+
209+
# End of https://www.toptal.com/developers/gitignore/api/osx,node,linux,windows,sam

bots/.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tests/*

bots/.prettierrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"printWidth": 80
3+
}

bots/package.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "@kleros/kleros-v2-bots",
3+
"version": "0.1.0",
4+
"description": "Automation, notification and other backend chores for Kleros v2.",
5+
"author": "Kleros",
6+
"license": "MIT",
7+
"packageManager": "yarn@3.1.0",
8+
"volta": {
9+
"node": "16.13.0"
10+
},
11+
"scripts": {
12+
"build": "sam build --use-container",
13+
"invoke": "sam local invoke IncrementorHandler -e src/functions/IncrementorHandler/mock.json",
14+
"test": "mocha -r ts-node/register 'test/**/*.ts'"
15+
},
16+
"engines": {
17+
"node": ">=16.13.0"
18+
},
19+
"devDependencies": {
20+
"@types/aws-lambda": "^8.10.98",
21+
"@types/node": "^14.14.25",
22+
"chai": "^4.3.6",
23+
"esbuild": "^0.14.42",
24+
"mocha": "^10.0.0",
25+
"ts-node": "^10.8.1",
26+
"typescript": "^4.1.3"
27+
}
28+
}

bots/samconfig.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version=0.1
2+
3+
[default.build.parameters]
4+
beta_features = true
5+
6+
[default.sync.parameters]
7+
beta_features = true
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { SQSHandler, SQSEvent, Context, SQSBatchResponse } from "aws-lambda";
2+
3+
/**
4+
* Event doc: https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html
5+
* @param {SQSEvent} event - API Gateway Lambda Proxy Input Format
6+
*
7+
* Context doc: https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-context.html
8+
* @param {Context} context
9+
*
10+
* Return doc: https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html#services-sqs-batchfailurereporting
11+
* @returns {SQSBatchResponse} object - SQS batch response
12+
*/
13+
export const handler: SQSHandler = async (event: SQSEvent, context: Context) => {
14+
console.log("Executing lambda handler on event: %O", event.Records);
15+
const response: SQSBatchResponse = {
16+
batchItemFailures: [
17+
{
18+
itemIdentifier: "helloWorld!",
19+
},
20+
],
21+
};
22+
return response;
23+
};
24+
25+
export default handler;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"Records": [
3+
{
4+
"messageId": "c80e8021-a70a-42c7-a470-796e1186f753",
5+
"receiptHandle": "AQEBJQ+/u6NsnT5t8Q/VbVxgdUl4TMKZ5FqhksRdIQvLBhwNvADoBxYSOVeCBXdnS9P+",
6+
"body": "{\"foo\":\"bar\"}",
7+
"attributes": {
8+
"AWSTraceHeader": "Root=1-5e58e4c3-71b539e3d6bd4aa29600bf67;Sampled=1",
9+
"ApproximateReceiveCount": "3",
10+
"SentTimestamp": "1529104986221",
11+
"SenderId": "594035263019",
12+
"ApproximateFirstReceiveTimestamp": "1529104986230"
13+
},
14+
"messageAttributes": {
15+
"testAttr": {
16+
"stringValue": "100",
17+
"binaryValue": "base64Str",
18+
"stringListValues": [],
19+
"binaryListValues": [],
20+
"dataType": "Number"
21+
},
22+
"testAttr2": {
23+
"stringValue": "100",
24+
"binaryValue": "base64Str",
25+
"dataType": "Number"
26+
}
27+
},
28+
"md5OfBody": "9bb58f26192e4ba00f01e2e7b136bbd8",
29+
"eventSource": "aws:sqs",
30+
"eventSourceARN": "arn:aws:sqs:us-west-2:594035263019:NOTFIFOQUEUE",
31+
"awsRegion": "us-west-2"
32+
}
33+
]
34+
}

bots/src/functions/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as hello } from './hello';

bots/template.yaml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
Transform: AWS::Serverless-2016-10-31
2+
Description: Incrementoor Bot
3+
Parameters:
4+
prefix:
5+
Type: AWS::SSM::Parameter::Value<String>
6+
Default: 'prefix'
7+
environment:
8+
Type: AWS::SSM::Parameter::Value<String>
9+
Default: 'environment'
10+
11+
Resources:
12+
IncrementorHandler:
13+
Type: AWS::Serverless::Function
14+
Metadata:
15+
BuildMethod: esbuild
16+
BuildProperties:
17+
Minify: false
18+
Target: "es2021"
19+
Sourcemap: true
20+
EntryPoints:
21+
- src/functions/IncrementorHandler/lambda.ts
22+
Properties:
23+
Handler: IncrementorHandler/lambda.handler
24+
CodeUri: .
25+
Timeout: 60
26+
Runtime: nodejs16.x
27+
Architectures:
28+
- x86_64
29+
Policies:
30+
- AWSLambdaExecute
31+
- Version: '2012-10-17'
32+
Statement:
33+
- Effect: Allow
34+
Action:
35+
- events:Put*
36+
Resource: '*'
37+
Events:
38+
IncrementorSQS:
39+
Type: SQS
40+
Properties:
41+
Queue: !GetAtt IncrementorSQS.Arn
42+
BatchSize: 5
43+
44+
IncrementorSQS:
45+
Type: AWS::SQS::Queue
46+
Properties:
47+
VisibilityTimeout: 43200

0 commit comments

Comments
 (0)