Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
135 commits
Select commit Hold shift + click to select a range
d1cf9c3
add requirement.txt file
kondurishiva Jun 28, 2025
829cea5
removed unused libraries
kondurishiva Jun 28, 2025
d59acb3
minor changes
kondurishiva Jun 28, 2025
7c6e38b
fix the table issue
kondurishiva Jun 28, 2025
8759012
adding lambda deploy
Jun 28, 2025
767aed4
adding lambda deploy
Jun 28, 2025
ec3f4a6
adding lambda deploy
Jun 28, 2025
0fb86ea
adding lambda deploy
Jun 28, 2025
fddb4f5
structure change
kondurishiva Jun 28, 2025
3479444
Merge branch 'backend_changes' of https://github.com/psrdotcom/aihack…
kondurishiva Jun 28, 2025
65c1b9b
adding lambda deploy
Jun 28, 2025
01759c0
adding lambda deploy
Jun 28, 2025
6832bda
adding lambda deploy
Jun 28, 2025
ac19ff6
adding lambda deploy
Jun 28, 2025
1457c7a
add entities code
kondurishiva Jun 28, 2025
40c919e
Merge branch 'backend_changes' of https://github.com/psrdotcom/aihack…
kondurishiva Jun 28, 2025
47278aa
password update
kondurishiva Jun 28, 2025
6d1a97d
adding automation for layer
Jun 28, 2025
0750d3d
adding automation for layer
Jun 28, 2025
36bce53
adding automation for layer
Jun 28, 2025
a93ef9a
adding automation for lambda
Jun 28, 2025
5be6924
Refactoring
kondurishiva Jun 28, 2025
e6d4898
error handling
kondurishiva Jun 28, 2025
b7254c4
database change
kondurishiva Jun 28, 2025
2847be3
password update
kondurishiva Jun 28, 2025
195f59d
debug log
kondurishiva Jun 28, 2025
e7e3f4f
debugging
kondurishiva Jun 28, 2025
2ff92b3
Added s3 debug log
kondurishiva Jun 28, 2025
369b6b4
adding new lambda
Jun 28, 2025
2a510bb
adding api code
Jun 28, 2025
6fb438c
updated code
kondurishiva Jun 28, 2025
b1c01c9
Merge branch 'backend_changes' of https://github.com/psrdotcom/aihack…
kondurishiva Jun 28, 2025
07dc606
Adding amplify code
Jun 28, 2025
2a27026
database schema changes
kondurishiva Jun 28, 2025
7bb7bf6
testing the submit api
kondurishiva Jun 28, 2025
385957a
new submit api
kondurishiva Jun 28, 2025
e3ec379
signature fix
kondurishiva Jun 28, 2025
f738c0f
corner case fix
kondurishiva Jun 28, 2025
7bfd990
test script update
kondurishiva Jun 28, 2025
c2b1b04
Fix Submit API
kondurishiva Jun 28, 2025
eb3665f
Pushed first commit for web_api
kmangalpally Jun 28, 2025
ab6842e
fix
kondurishiva Jun 28, 2025
f8cc364
Merge branch 'backend_changes' of https://github.com/psrdotcom/aihack…
kondurishiva Jun 28, 2025
e3f2ee0
duplicate entity
kondurishiva Jun 28, 2025
6ebb4c4
Changed main.py to web_api.py and added package for running fastAPI i…
kmangalpally Jun 28, 2025
ebe2361
making layer dynamic
Jun 28, 2025
dc358cd
Merge branch 'backend_changes' of https://github.com/psrdotcom/aihack…
kmangalpally Jun 28, 2025
2158b13
making layer dynamic
Jun 28, 2025
5b6e2b4
Merge branch 'backend_changes' of https://github.com/psrdotcom/aihack…
kmangalpally Jun 28, 2025
01a4d63
making layer dynamic
Jun 28, 2025
4663f10
submit api lamba fix
kondurishiva Jun 28, 2025
b37dbc9
Merge branch 'backend_changes' of https://github.com/psrdotcom/aihack…
kondurishiva Jun 28, 2025
62ff738
making layer dynamic
Jun 28, 2025
05086b3
submit API logging
kondurishiva Jun 28, 2025
e955f53
Merge branch 'backend_changes' of https://github.com/psrdotcom/aihack…
kondurishiva Jun 28, 2025
bbab44f
adding api
Jun 28, 2025
5358819
filenames changes
kondurishiva Jun 28, 2025
fd75d1b
Merge branch 'backend_changes' of https://github.com/psrdotcom/aihack…
kondurishiva Jun 28, 2025
e3081e1
fix encoding issue
kondurishiva Jun 28, 2025
037a927
Fix CSV upload and add requests-toolbelt dependency
kondurishiva Jun 28, 2025
c8502ce
adding condition to update layer version
Jun 28, 2025
ea1f7d4
Changing packages as web_api was throwing error
kmangalpally Jun 28, 2025
48b26df
Merge branch 'backend_changes' of https://github.com/psrdotcom/aihack…
kmangalpally Jun 28, 2025
69b92e8
Error fix
kmangalpally Jun 28, 2025
1a4c73d
library fix
kondurishiva Jun 28, 2025
885e446
library conflict fix
kondurishiva Jun 28, 2025
840ed19
file read debug
kondurishiva Jun 28, 2025
9d66bb9
adding condition to update layer version
Jun 28, 2025
07e02f5
adding condition to update layer version
Jun 28, 2025
c93a1e3
added trace
kondurishiva Jun 28, 2025
f0bd074
Merge branch 'backend_changes' of https://github.com/psrdotcom/aihack…
kondurishiva Jun 28, 2025
c9c95bd
Another trial
kmangalpally Jun 28, 2025
f2f8732
parsing fix
kondurishiva Jun 28, 2025
5859ee9
Merge branch 'backend_changes' of https://github.com/psrdotcom/aihack…
kondurishiva Jun 28, 2025
c3453f8
Another fix
kmangalpally Jun 28, 2025
d650ddb
Merge branch 'backend_changes' of https://github.com/psrdotcom/aihack…
kmangalpally Jun 28, 2025
e70a542
removed redanduct print
kondurishiva Jun 28, 2025
f1758d6
Merge branch 'backend_changes' of https://github.com/psrdotcom/aihack…
kondurishiva Jun 28, 2025
59bf78f
fix
kondurishiva Jun 28, 2025
fb785f5
fix2
kondurishiva Jun 28, 2025
b563ff9
Another fixv2
kmangalpally Jun 28, 2025
7011761
updated response data
kondurishiva Jun 28, 2025
4d836cd
response fix
kondurishiva Jun 28, 2025
d1d0d32
parser optimization
kondurishiva Jun 28, 2025
6aa3186
file space issue
kondurishiva Jun 28, 2025
15a20c6
added region
kondurishiva Jun 28, 2025
19c0bcb
improved logging
kondurishiva Jun 28, 2025
04d24a8
file name changes
kondurishiva Jun 28, 2025
4c9a261
remove headers
kondurishiva Jun 28, 2025
1eef580
endpoint test
kondurishiva Jun 28, 2025
1d12c22
error fix
kondurishiva Jun 28, 2025
b5803c3
debug logs
kondurishiva Jun 28, 2025
f00853d
IAM role update
kondurishiva Jun 28, 2025
c207175
datetime fix
kondurishiva Jun 28, 2025
499d8ea
Pushing changes
kmangalpally Jun 28, 2025
a932cc4
new keyphrase table
kondurishiva Jun 28, 2025
0c4dc88
library fix
kondurishiva Jun 28, 2025
0e9734c
adding new lambda
Jun 28, 2025
f961247
key phrase fix
kondurishiva Jun 28, 2025
40a0484
Merge branch 'backend_changes' of https://github.com/psrdotcom/aihack…
kondurishiva Jun 28, 2025
1305826
minor fix
kondurishiva Jun 28, 2025
b3b6b42
adding new lambda
Jun 28, 2025
fcb2a98
Trial changes
kmangalpally Jun 28, 2025
203eadf
data format change
kondurishiva Jun 28, 2025
6985b8a
Merge branch 'backend_changes' into karthikeya
kmangalpally Jun 28, 2025
e9b6dbb
Merge pull request #8 from psrdotcom/karthikeya
kmangalpally Jun 28, 2025
217a941
pushing changes
kmangalpally Jun 28, 2025
d80c875
pushing changes
kmangalpally Jun 28, 2025
bdb13b2
adding an api
Jun 28, 2025
7a7a25c
adding an api
Jun 28, 2025
7d9b9c5
database fix
kmangalpally Jun 28, 2025
b3e5efb
database fix
kmangalpally Jun 28, 2025
47c2cdb
adding an api
Jun 28, 2025
55dd401
integrate relevance agent
kondurishiva Jun 28, 2025
890e8fa
Merge branch 'backend_changes' of https://github.com/psrdotcom/aihack…
kondurishiva Jun 28, 2025
ce2b9f2
trial v1
kmangalpally Jun 28, 2025
3dc16d3
debug the agent
kondurishiva Jun 28, 2025
aac33dd
trial v2
kmangalpally Jun 28, 2025
793bcac
trial v3
kmangalpally Jun 28, 2025
f400098
trial v4
kmangalpally Jun 28, 2025
77cdee6
fail safe
kondurishiva Jun 28, 2025
5da81cd
Merge branch 'backend_changes' of https://github.com/psrdotcom/aihack…
kondurishiva Jun 28, 2025
caca4f3
suppress agent error
kondurishiva Jun 28, 2025
49fdfb1
subpress
kondurishiva Jun 28, 2025
500baf5
removed comments
kondurishiva Jun 28, 2025
3abbb96
cluster service
kondurishiva Jun 29, 2025
53979e3
Create feed.py
kondurishiva Jun 29, 2025
113c72e
adding api
Jun 29, 2025
7bd0203
api fix
kondurishiva Jun 29, 2025
c200d83
Merge branch 'backend_changes' of https://github.com/psrdotcom/aihack…
kondurishiva Jun 29, 2025
92c6a9b
removed unused code
kondurishiva Jun 29, 2025
8eeae79
update response
kondurishiva Jun 29, 2025
6030131
get feed response changes
kondurishiva Jun 29, 2025
30cacb9
Removed unused files
kondurishiva Jun 29, 2025
52b6f51
Merge branch 'main' into backend_changes
kondurishiva Jun 29, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Deploy API Gateway

on:
push:
paths:
- 'api/*'

jobs:
deploy-api:
runs-on: ubuntu-latest

steps:
- name: Checkout repo
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install boto3
- name: Run API deployment script
env:
AWS_ACCESS_KEY_ID: AKIAT5VEV4FHFQQJBZVX
AWS_SECRET_ACCESS_KEY: o56LCVEDcTPD8RgU2iWtz8SBklKa5DqQ6+nCYawf
AWS_REGION: us-east-1 # or your region
run: |
python3 api/deploy-api.py
95 changes: 95 additions & 0 deletions .github/workflows/lambda.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: Deploy Lambdas

on:
push:
branches:
- main
- backend_changes

env:
LAMBDA_DIR: backend
DEPLOY_BUCKET: hackathon-lambda-ap-ai-cyberark

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.12'

- name: Install AWS CLI
run: pip install awscli

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: AKIAT5VEV4FHFQQJBZVX
aws-secret-access-key: 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
aws-region: us-east-1

- name: Deploy Lambda Functions (No dependencies)
run: |
LAYER_ARN=$(aws lambda list-layer-versions \
--layer-name "my-python-layer" \
--query 'LayerVersions[0].LayerVersionArn' \
--output text)

echo "Using latest layer version: $LAYER_ARN"
for dir in "$LAMBDA_DIR"/*/; do
dir=${dir%/}
function_name=$(basename "$dir")
entry_point="$dir/${function_name}.py"

if [ ! -f "$entry_point" ]; then
echo "Skipping $function_name: $entry_point not found."
continue
fi

echo "Packaging Lambda: $function_name"

build_dir="/tmp/${function_name}_build"
zip_file="/tmp/${function_name}.zip"

rm -rf "$build_dir"
mkdir -p "$build_dir"

# Copy Lambda source file
cp -r "$dir"/* "$build_dir/"

# Copy all top-level shared files from backend (excluding directories and requirements.txt)
find "$LAMBDA_DIR" -maxdepth 1 -type f ! -name "requirements.txt" -exec cp {} "$build_dir/" \;

# Zip build directory
cd "$build_dir"
zip -r "$zip_file" . > /dev/null
cd -

# Upload zip to S3
aws s3 cp "$zip_file" "s3://${DEPLOY_BUCKET}/${function_name}.zip"

# Deploy Lambda
if aws lambda get-function --function-name "$function_name" > /dev/null 2>&1; then
echo "Updating Lambda: $function_name"
aws lambda update-function-code \
--function-name "$function_name" \
--s3-bucket "$DEPLOY_BUCKET" \
--s3-key "${function_name}.zip"
else
echo "Creating Lambda: $function_name"
aws lambda create-function \
--function-name "$function_name" \
--runtime python3.12 \
--role "arn:aws:iam::269854564686:role/hackathon-lambda-role" \
--handler "${function_name}.lambda_handler" \
--code S3Bucket="$DEPLOY_BUCKET",S3Key="${function_name}.zip" \
--timeout 900 \
--vpc-config SubnetIds=subnet-02e62e34308bb07d5,subnet-0534b99dd34e646f1,SecurityGroupIds=sg-0b9a6b812b30a1107 \
--layers "$LAYER_ARN"
fi
done
88 changes: 88 additions & 0 deletions .github/workflows/layer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Build Lambda Layer

on:
push:
paths:
- 'backend/requirements.txt'
workflow_dispatch:

jobs:
build-and-publish-layer:
runs-on: ubuntu-latest

env:
LAYER_NAME: my-python-layer
PYTHON_VERSION: python3.12
S3_KEY: layers/layer.zip

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install dependencies to python/
run: |
mkdir -p python
pip install -r backend/requirements.txt --platform manylinux2014_x86_64 --only-binary=:all: -t python/

- name: Clean up unnecessary files
run: |
find python/ -type d -name "__pycache__" -exec rm -rf {} +
find python/ -type d -name "tests" -exec rm -rf {} +
find python/ -type f -name "*.pyc" -delete

- name: Zip the layer
run: zip -r layer.zip python

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: AKIAT5VEV4FHFQQJBZVX
aws-secret-access-key: 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
aws-region: us-east-1

- name: Upload zip to S3
run: |
aws s3 cp layer.zip s3://hackathon-lambda-ap-ai-cyberark/${{ env.S3_KEY }}

- name: Publish Lambda Layer from S3
run: |
aws lambda publish-layer-version \
--layer-name ${{ env.LAYER_NAME }} \
--description "Dependencies from backend/requirements.txt" \
--content S3Bucket=hackathon-lambda-ap-ai-cyberark,S3Key=${{ env.S3_KEY }} \
--compatible-runtimes ${{ env.PYTHON_VERSION }}

- name: Upload artifact (optional)
uses: actions/upload-artifact@v4
with:
name: lambda-layer
path: layer.zip

- name: Get latest layer version ARN
id: get-layer-version
run: |
LAYER_ARN=$(aws lambda list-layer-versions --layer-name ${{ env.LAYER_NAME }} \
--query 'LayerVersions[0].LayerVersionArn' --output text)
echo "layer_arn=$LAYER_ARN" >> "$GITHUB_OUTPUT"

- name: List functions using the layer
id: list-functions
run: |
FUNCTIONS=$(aws lambda list-functions --query \
"Functions[?Layers && contains(join(',', Layers[].Arn), '${{ env.LAYER_NAME }}')].FunctionName" \
--output text)
echo "functions=$FUNCTIONS" >> "$GITHUB_OUTPUT"

- name: Update functions to use latest layer version
run: |
for function in ${{ steps.list-functions.outputs.functions }}; do
echo "Updating $function..."
aws lambda update-function-configuration \
--function-name "$function" \
--layers ${{ steps.get-layer-version.outputs.layer_arn }}
done
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,6 @@ cython_debug/
.cursorignore
.cursorindexingignore
.DS_Store

node_modules
package-lock.json
1 change: 0 additions & 1 deletion amplify.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
branch = sys.argv[2]
repo_owner, repo_name = repo_full.split('/')
app_name = f"amplify-{repo_name}"

client = boto3.client('amplify','us-east-1')
print(GITHUB_PAT)

Expand Down
144 changes: 144 additions & 0 deletions api/deploy-api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import boto3
import json
import os

REGION = "us-east-1"
STAGE = "prod"
ACCOUNT_ID = "269854564686"

apigateway = boto3.client("apigateway", region_name=REGION)
lambda_client = boto3.client("lambda", region_name=REGION)

def get_or_create_api(api_name):
apis = apigateway.get_rest_apis()["items"]
for api in apis:
if api["name"] == api_name:
print(f"Found API: {api_name}")
return api["id"]

print(f"Creating API: {api_name}")
response = apigateway.create_rest_api(name=api_name)
return response["id"]

def get_or_create_resource(api_id, full_path):
# Normalize and split nested path: "users/{userId}" => ["users", "{userId}"]
parts = [p for p in full_path.strip("/").split("/") if p]
resources = apigateway.get_resources(restApiId=api_id)["items"]

# Build a path-to-id map
path_map = {res["path"]: res["id"] for res in resources}
parent_path = ""
parent_id = path_map["/"] # root path

for part in parts:
current_path = f"{parent_path}/{part}" if parent_path else f"/{part}"
if current_path in path_map:
parent_id = path_map[current_path]
else:
print(f"Creating resource: {current_path}")
response = apigateway.create_resource(
restApiId=api_id,
parentId=parent_id,
pathPart=part
)
parent_id = response["id"]
path_map[current_path] = parent_id
parent_path = current_path

return parent_id


def method_exists(api_id, resource_id, http_method):
try:
apigateway.get_method(
restApiId=api_id,
resourceId=resource_id,
httpMethod=http_method
)
return True
except apigateway.exceptions.NotFoundException:
return False

def add_lambda_permission(lambda_name, api_id, method, path):
statement_id = f"{lambda_name.lower()}-{method.lower()}"
try:
lambda_client.add_permission(
FunctionName=lambda_name,
StatementId=statement_id,
Action="lambda:InvokeFunction",
Principal="apigateway.amazonaws.com",
SourceArn=f"arn:aws:execute-api:{REGION}:{ACCOUNT_ID}:{api_id}/*/{method}/{path}"
)
print(f"Added permission to Lambda {lambda_name} for method {method} /{path}")
except lambda_client.exceptions.ResourceConflictException:
# Permission already exists
print(f"Permission already exists for Lambda {lambda_name} and method {method} /{path}")

def setup_method(api_id, resource_id, method_def, path):
method = method_def["httpMethod"].upper()
lambda_name = method_def["lambdaFunctionName"]
auth_type = method_def.get("authorizationType", "NONE")
lambda_arn = f"arn:aws:lambda:{REGION}:{ACCOUNT_ID}:function:{lambda_name}"

if method_exists(api_id, resource_id, method):
print(f"Method {method} already exists for /{path}, skipping method creation.")
else:
print(f"Creating method {method} for /{path}")
apigateway.put_method(
restApiId=api_id,
resourceId=resource_id,
httpMethod=method,
authorizationType=auth_type
)

print(f"Setting integration for {method} /{path}")
apigateway.put_integration(
restApiId=api_id,
resourceId=resource_id,
httpMethod=method,
type="AWS_PROXY",
integrationHttpMethod="POST",
uri=f"arn:aws:apigateway:{REGION}:lambda:path/2015-03-31/functions/{lambda_arn}/invocations"
)

add_lambda_permission(lambda_name, api_id, method, path)

def deploy_api(api_id):
print(f"Deploying API {api_id} to stage: {STAGE}")
apigateway.create_deployment(
restApiId=api_id,
stageName=STAGE
)

def main():
# Use script folder as working directory to find JSON files
script_dir = os.path.dirname(os.path.abspath(__file__))

deploy_apis = set()

# Loop all JSON files in current folder
for file in os.listdir(script_dir):
if not file.endswith(".json"):
continue

json_path = os.path.join(script_dir, file)
with open(json_path) as f:
config = json.load(f)

api_name = config["apiName"]
resource_path = config["resourcePath"]
method_def = config["method"]
should_deploy = config.get("deploy", False)

api_id = get_or_create_api(api_name)
resource_id = get_or_create_resource(api_id, resource_path)
setup_method(api_id, resource_id, method_def, resource_path)

if should_deploy:
deploy_apis.add(api_id)

for api_id in deploy_apis:
deploy_api(api_id)

if __name__ == "__main__":
main()
10 changes: 10 additions & 0 deletions api/get-value.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"apiName": "hackathon",
"resourcePath": "get-value",
"method": {
"httpMethod": "GET",
"authorizationType": "NONE",
"lambdaFunctionName": "Submit"
},
"deploy": true
}
Loading