From bc78455ccf57bf116707350aa2bfc9ebcf1da555 Mon Sep 17 00:00:00 2001 From: Krzysztof Banasiak Date: Thu, 28 Dec 2023 13:38:47 +0100 Subject: [PATCH] feat: Deploy backend lambda --- .github/workflows/cdk-deploy.yaml | 10 +++------- app.py | 3 +++ backend/backend_stack.py | 15 +++++++++++++++ {vectorstore => backend/lambda}/__init__.py | 0 backend/lambda/backend_lambda.py | 12 ++++++++++++ backend/model_stack.py | 9 +++++++++ 6 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 backend/backend_stack.py rename {vectorstore => backend/lambda}/__init__.py (100%) create mode 100644 backend/lambda/backend_lambda.py create mode 100644 backend/model_stack.py diff --git a/.github/workflows/cdk-deploy.yaml b/.github/workflows/cdk-deploy.yaml index b2269a9..0a3955c 100644 --- a/.github/workflows/cdk-deploy.yaml +++ b/.github/workflows/cdk-deploy.yaml @@ -47,10 +47,6 @@ jobs: run: | cdk deploy ChatbotVpcStack --require-approval never -# - name: Deploy Chatbot Vpc -# uses: youyo/aws-cdk-github-actions@v2 -# with: -# cdk_subcommand: deploy -# cdk_stack: ChatbotVpcStack -# cdk_args: "--require-approval never" -# actions_comment: false + - name: Deploy Chatbot Backend + run: | + cdk deploy ChatbotBackendStack --require-approval never diff --git a/app.py b/app.py index e2421a1..a8f2013 100644 --- a/app.py +++ b/app.py @@ -2,6 +2,7 @@ import aws_cdk as cdk +from backend.backend_stack import BackendStack from base.github_trust_stack import GitHubTrustStack from base.vpc_stack import VpcStack @@ -9,6 +10,8 @@ # Create the GitHub trust stack in AWS account. GitHubTrustStack(app, "ChatbotGithubTrustStack") + VpcStack(app, "ChatbotVpcStack") +BackendStack(app, "ChatbotBackendStack") app.synth() diff --git a/backend/backend_stack.py b/backend/backend_stack.py new file mode 100644 index 0000000..0f9d5d5 --- /dev/null +++ b/backend/backend_stack.py @@ -0,0 +1,15 @@ +from aws_cdk import Stack, aws_lambda +from constructs import Construct + + +class BackendStack(Stack): + def __init__(self, scope: Construct, id: str, **kwargs): + super().__init__(scope, id, **kwargs) + + aws_lambda.Function( + scope=self, + id="ChatbotBackendLambda", + runtime=aws_lambda.Runtime.PYTHON_3_11, + handler="backend_lambda.handler", + code=aws_lambda.Code.from_asset("backend/lambda"), + ) diff --git a/vectorstore/__init__.py b/backend/lambda/__init__.py similarity index 100% rename from vectorstore/__init__.py rename to backend/lambda/__init__.py diff --git a/backend/lambda/backend_lambda.py b/backend/lambda/backend_lambda.py new file mode 100644 index 0000000..cdf8e95 --- /dev/null +++ b/backend/lambda/backend_lambda.py @@ -0,0 +1,12 @@ +import json + + +def handler(event, context): + print('request: {}'.format(json.dumps(event))) + return { + 'statusCode': 200, + 'headers': { + 'Content-Type': 'text/plain' + }, + 'body': 'Hello, CDK! You have hit {}\n'.format(event['path']) + } diff --git a/backend/model_stack.py b/backend/model_stack.py new file mode 100644 index 0000000..ee485ea --- /dev/null +++ b/backend/model_stack.py @@ -0,0 +1,9 @@ +from aws_cdk import Stack +from constructs import Construct + + +class ModelStack(Stack): + def __init__(self, scope: Construct, id: str, **kwargs): + super().__init__(scope, id, **kwargs) + + \ No newline at end of file