Skip to content
This repository was archived by the owner on Mar 12, 2025. It is now read-only.

Commit 57b24f9

Browse files
#1 - Update code base to sync user skills b/w member api and u-bahn
1 parent bada435 commit 57b24f9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+6344
-2722
lines changed

.gitignore

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
9+
# Diagnostic reports (https://nodejs.org/api/report.html)
10+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11+
12+
# Runtime data
13+
pids
14+
*.pid
15+
*.seed
16+
*.pid.lock
17+
18+
# Directory for instrumented libs generated by jscoverage/JSCover
19+
lib-cov
20+
21+
# Coverage directory used by tools like istanbul
22+
coverage
23+
*.lcov
24+
25+
# nyc test coverage
26+
.nyc_output
27+
28+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29+
.grunt
30+
31+
# Bower dependency directory (https://bower.io/)
32+
bower_components
33+
34+
# node-waf configuration
35+
.lock-wscript
36+
37+
# Compiled binary addons (https://nodejs.org/api/addons.html)
38+
build/Release
39+
40+
# Dependency directories
41+
node_modules/
42+
jspm_packages/
43+
44+
# Snowpack dependency directory (https://snowpack.dev/)
45+
web_modules/
46+
47+
# TypeScript cache
48+
*.tsbuildinfo
49+
50+
# Optional npm cache directory
51+
.npm
52+
53+
# Optional eslint cache
54+
.eslintcache
55+
56+
# Microbundle cache
57+
.rpt2_cache/
58+
.rts2_cache_cjs/
59+
.rts2_cache_es/
60+
.rts2_cache_umd/
61+
62+
# Optional REPL history
63+
.node_repl_history
64+
65+
# Output of 'npm pack'
66+
*.tgz
67+
68+
# Yarn Integrity file
69+
.yarn-integrity
70+
71+
# dotenv environment variables file
72+
.env
73+
.env.test
74+
75+
# parcel-bundler cache (https://parceljs.org/)
76+
.cache
77+
.parcel-cache
78+
79+
# Next.js build output
80+
.next
81+
out
82+
83+
# Nuxt.js build / generate output
84+
.nuxt
85+
dist
86+
87+
# Gatsby files
88+
.cache/
89+
# Comment in the public line in if your project uses Gatsby and not Next.js
90+
# https://nextjs.org/blog/next-9-1#public-directory-support
91+
# public
92+
93+
# vuepress build output
94+
.vuepress/dist
95+
96+
# Serverless directories
97+
.serverless/
98+
99+
# FuseBox cache
100+
.fusebox/
101+
102+
# DynamoDB Local files
103+
.dynamodb/
104+
105+
# TernJS port file
106+
.tern-port
107+
108+
# Stores VSCode versions used for testing VSCode extensions
109+
.vscode-test
110+
111+
# yarn v2
112+
.yarn/cache
113+
.yarn/unplugged
114+
.yarn/build-state.yml
115+
.yarn/install-state.gz
116+
.pnp.*
117+
118+
# api.env
119+
api.env
120+
121+
# macOS files
122+
.DS_Store

.nvmrc

Lines changed: 0 additions & 1 deletion
This file was deleted.

README.md

Lines changed: 104 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,120 @@
11
# member-skills-sync-lambda
22

33
## Prerequisites
4-
1. Amazon DynamoDB table for the streaming and sending member skills data to Amazon Lambda exists and the ARN is known (please enable the streaming on DynamoDB with View type "New and old images" - see screen-shot in Verification Document if required).
5-
2. Amazon ElasticSearch domain for posting the member skills data already exists and endpoint is known.
6-
3. AWS Lambda IAM role that has the privilege (permission policies) to read the stream from DynamodDB already exists and ARN is known.
7-
4. Amazon ElasticSearch domain access policy has been configured so that AWS Lambda IAM role can do necessary action to post data to ElasticSearch and for unit test purpose, either using IP address or Serverless Agent IAM User below is given access to post data to ElasticSearch.
8-
5. Serverless Framework has been installed. If not yet done, please follow this [link](https://serverless.com/framework/docs/providers/aws/guide/installation/).
9-
6. Serverless Agent IAM User has been configured properly and its access key ID and its agent secret access key is known, please follow this [link](https://serverless.com/framework/docs/providers/aws/guide/credentials/) to setup one if not yet done.
10-
7. All the instructions below are using Node v10.16.3.
11-
12-
## Environment Variables
13-
Please follow this instruction to setup the required environment variables. We are using Linux terminal in this example.
14-
15-
First you need to setup environment variables for AWS credentials. For review purpose, actually you don't need to create a new user for severless agent, just use your AWS account's access key and secret access key which already have full-access to all AWS services.
16-
```
17-
export AWS_ACCESS_KEY_ID=<your access key id>
18-
export AWS_SECRET_ACCESS_KEY=<your secret access key>
19-
```
20-
For the sake of unit testing to run, running your lambda function locally, and deploying your lambda's environment variables, please also setup 9 more environment variables below in your terminal (using export command same as above).
21-
1. ES_URL --> Endpoint of your elastic search
22-
2. ES_REGION --> Region of your elastic search e.g. us-east-1
23-
3. ES_SKILLS_INDEX --> ElasticSearch Index for member entered skills documents
24-
4. ES_SKILLS_MAPPING --> ElasticSearch document type for member entered skills index
25-
7. DB_ENTERED_SKILLS_STREAM --> ARN of DynamoDB table MemberEnteredSkills stream
26-
8. DB_AGGREGATED_SKILLS_STREAM --> ARE of DynamoDB table MemberAggregatedSkills stream
27-
9. LAMBDA_ROLE --> ARN of IAM Role to be used when executing Lambda
28-
29-
## Change the serverless.yml to fit your environment
30-
Please open serverless.yml from the project and modify following value in case you don't want to use environment variables:
31-
1. role (under index.syncSkills) --> ARN of your AWS Lambda IAM Role
32-
2. arn (under stream) --> ARN of your DynamoDB table stream
33-
3. ES_* (under environment) --> This is by default populated by environment variables, feel free to change if needed
34-
4. DB_* (under environment) --> This is by default populated by environment variables, feel free to change if needed
35-
5. Please also modify stage and region to fit your needs
36-
37-
## Install Dependencies and Run Lint
38-
1. run the following command to install the dependencies
39-
```
4+
5+
- Nodejs(v12+)
6+
7+
## Configuration
8+
9+
Configuration for the skill record processor is at `config/default.js`.
10+
The following parameters can be set in config files or in env variables:
11+
12+
- UBAHN_API_URL: The ubahn api url, default value: 'https://api.topcoder-dev.com/v5'
13+
- TC_API_URL: The topcoder api url, default value: 'https://api.topcoder-dev.com'
14+
- AUTH0_URL: The auth0 url, default value: 'https://topcoder-dev.auth0.com/oauth/token'
15+
- AUTH0_UBAHN_AUDIENCE: The auth0 audience for accessing ubahn api(s), default value: 'https://u-bahn.topcoder-dev.com'
16+
- AUTH0_TOPCODER_AUDIENCE: The auth0 audience for accessing tc api(s), default value: 'https://m2m.topcoder-dev.com/'
17+
- AUTH0_CLIENT_ID: The auth0 client id
18+
- AUTH0_CLIENT_SECRET: The auth0 client secret
19+
- VALID_ISSUERS: The valid issuer of tokens, a json array contains valid issuer.
20+
- TOKEN_CACHE_TIME: Auth0 token cache time, used to get TC M2M token
21+
- AUTH0_PROXY_SERVER_URL: Proxy Auth0 URL, used to get TC M2M token
22+
- SKILL_PROVIDER_NAME: The skill provider name, default value: Topcoder
23+
- SLEEP_TIME: The pause time between two create operations, default value: 1000 ms
24+
25+
## Local Test
26+
27+
- install the dependencies
28+
29+
``` bash
4030
npm install
4131
```
42-
2. To run linter if required
43-
```
44-
npm run lint
4532

33+
- run linters if required
34+
35+
``` bash
36+
npm run lint
4637
npm run lint:fix # To fix possible lint errors
4738
```
4839

49-
## Unit Test
50-
Make sure you have properly setup the [environment variables](#environment-variables) and [installing dependencies](#install-dependencies-and-run-lint). Run `npm run test` to run the unit test.
40+
- run test
5141

52-
## Run lambda locally
53-
1. Make sure you have properly setup the [environment variables](#environment-variables) and [installing dependencies](#install-dependencies-and-run-lint).
54-
55-
2. Run command `npm run test-data` to generate test data.(Important step!! The provided test data have different eventSourceARN which are different with your environment variables. The lambda function need to use eventSourceARN to distinguish ES index.)
56-
57-
3. Then, Run the following to invoke lambda locally.
58-
```
59-
serverless invoke local -f sync -p test_data/createEnteredSkillsEvent.json
60-
serverless invoke local -f sync -p test_data/updateEnteredSkillsEvent.json
61-
serverless invoke local -f sync -p test_data/deleteEnteredSkillsEvent.json
62-
serverless invoke local -f sync -p test_data/createMemberAggregatedSkillsEvent.json
63-
serverless invoke local -f sync -p test_data/updateMemberAggregatedSkillsEvent.json
64-
serverless invoke local -f sync -p test_data/deleteMemberAggregatedSkillsEvent.json
42+
``` bash
43+
npm test
6544
```
66-
Please note that even if the lambda is invoked locally using test data, the data is still being posted to ElasticSearch in AWS based on environment variables above. In order for the local invocation to work properly, the serverless agent that is used by serverless command has to have privilege to post the data to ElasticSearch or the access policy for the ElasticSearch is configured to allow any AWS principal to post the data but restricted by condition e.g. by using IpAddress.
6745

6846
## Deploy
69-
When all the things mentioned above have been done, please run the following:
70-
```
71-
serverless deploy
72-
```
73-
Feel free to use flag `--verbose` after `serverless deploy` if you want to know more information about your deployment.
7447

75-
You can also modify the lambda code if required and the redeployment is as simple as running `serverless deploy` again.
48+
- make sure you have installed the dependencies
49+
- make sure you have aws credentials in you environment
50+
- update the `.env` file, set `AUTH0_CLIENT_ID` and `AUTH0_CLIENT_SECRET` and other configurations that you want to change
51+
52+
``` bash
53+
npm run deploy
54+
```
7655

7756
## Verification
78-
Please read verification document for screen shot of enabling DynamoDB table stream, unit test result, deployment results, and results of manual testing on the lambda.
57+
58+
After deploy, you can open [aws lambda config](https://console.aws.amazon.com/lambda/home?region=us-east-1#/functions/member-v5user-skill-sync?tab=testing) to test, here is the example event json `{
59+
"Records":[
60+
{
61+
"eventID":"904156e21aa4f1085f970bfdbcbfb483",
62+
"eventName":"MODIFY",
63+
"eventVersion":"1.1",
64+
"eventSource":"aws:dynamodb",
65+
"awsRegion":"us-east-1",
66+
"dynamodb":{
67+
"ApproximateCreationDateTime":1618587935,
68+
"Keys":{
69+
"userId":{
70+
"N":"40153932"
71+
}
72+
},
73+
"NewImage":{
74+
"skills":{
75+
"S":"{\"110\":{\"tagName\":null,\"hidden\":false,\"score\":1.0,\"sources\":[]},\"117\":{\"tagName\":null,\"hidden\":false,\"score\":1.0,\"sources\":[]}}"
76+
},
77+
"userHandle":{
78+
"S":"sachin-kumar"
79+
},
80+
"updatedBy":{
81+
"S":"40153932"
82+
},
83+
"userId":{
84+
"N":"40153932"
85+
},
86+
"handleLower":{
87+
"S":"sachin-kumar"
88+
},
89+
"updatedAt":{
90+
"N":"1618587934734"
91+
}
92+
},
93+
"OldImage":{
94+
"skills":{
95+
"S":"{\"110\":{\"tagName\":null,\"hidden\":false,\"score\":1.0,\"sources\":[]}}"
96+
},
97+
"userHandle":{
98+
"S":"sachin-kumar"
99+
},
100+
"updatedBy":{
101+
"S":"40153932"
102+
},
103+
"userId":{
104+
"N":"40153932"
105+
},
106+
"handleLower":{
107+
"S":"sachin-kumar"
108+
},
109+
"updatedAt":{
110+
"N":"1618586677911"
111+
}
112+
},
113+
"SequenceNumber":"9298848500000000010313715543",
114+
"SizeBytes":394,
115+
"StreamViewType":"NEW_AND_OLD_IMAGES"
116+
},
117+
"eventSourceARN":":table/MemberEnteredSkills/stream/2018-09-21T08:58:50.405"
118+
}
119+
]
120+
}`

Verification.md

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)