-
Notifications
You must be signed in to change notification settings - Fork 10
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
7997f70
commit ac046ff
Showing
10 changed files
with
118 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env python3 | ||
from aws_cdk import App | ||
|
||
from s3trigger.s3trigger_stack import S3TriggerStack | ||
|
||
app = App() | ||
S3TriggerStack(app, "s3trigger") | ||
|
||
app.synth() |
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,23 @@ | ||
#!/bin/bash | ||
|
||
# Setting up proxy and git | ||
export HTTPS_PROXY=http://proxy01.pnl.gov:3128 | ||
export https_proxy=http://proxy01.pnl.gov:3128 | ||
export AWS_PROFILE=AdministratorAccess-305402452870 | ||
export AWS_DEFAULT_REGION=us-west-2 | ||
|
||
# Configure Git credential helper | ||
git config --global credential.helper '!aws --profile AdministratorAccess-305402452870 codecommit credential-helper $@' | ||
|
||
# Start docker engine | ||
docker --version | ||
|
||
#virtual environment setup | ||
python -m venv venv | ||
source venv/bin/activate | ||
|
||
#cdk library setup | ||
pip install aws-cdk-lib==2.90.0 | ||
|
||
# AWS configuration on CLI | ||
aws configure sso |
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,3 @@ | ||
{ | ||
"app": "python3 app.py" | ||
} |
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,21 @@ | ||
FROM public.ecr.aws/lambda/python:3.11 | ||
|
||
# Copy requirements.txt | ||
#COPY requirements.txt ${LAMBDA_TASK_ROOT} | ||
|
||
# Copy function code | ||
COPY lambda_handler.py ${LAMBDA_TASK_ROOT} | ||
ADD python_wrapper ${LAMBDA_TASK_ROOT}/python_wrapper | ||
|
||
#Setup Proxy | ||
#RUN export HTTPS_PROXY=http://proxy01.pnl.gov:3128 | ||
#RUN export https_proxy=http://proxy01.pnl.gov:3128 | ||
# Install the specified packages | ||
#RUN export HTTP_PROXY=http://proxy01.pnl.gov:3128 | ||
#RUN export http_proxy=http://proxy01.pnl.gov:3128 | ||
RUN pip install --upgrade pip | ||
#RUN pip install -r ${LAMBDA_TASK_ROOT}/requirements.txt | ||
|
||
|
||
# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile) | ||
#CMD [ "lambda_handler.main" ] |
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 @@ | ||
import python_wrapper | ||
def main(event, context): | ||
# save event to logs | ||
print(event) | ||
|
||
return { | ||
'statusCode': 200, | ||
'body': event | ||
} |
8 changes: 8 additions & 0 deletions
8
cdk-projects/lambda-container/lambda/python_wrapper/__init__.py
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 @@ | ||
import exago | ||
exago.initialize("opflow") | ||
opf = exago.OPFLOW() | ||
opf.read_mat_power_data('datafiles/case9/case9mod.m') | ||
opf.solve() | ||
opf.print_solution() | ||
del opf | ||
exago.finalize() |
8 changes: 8 additions & 0 deletions
8
cdk-projects/lambda-container/lambda/python_wrapper/lambda_exago.py
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 @@ | ||
import exago | ||
exago.initialize("opflow") | ||
opf = exago.OPFLOW() | ||
opf.read_mat_power_data('datafiles/case9/case9mod.m') | ||
opf.solve() | ||
opf.print_solution() | ||
del opf | ||
exago.finalize() |
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,2 @@ | ||
aws-cdk-lib>=2.0.0 | ||
constructs>=10.0.0 |
Empty file.
35 changes: 35 additions & 0 deletions
35
cdk-projects/lambda-container/s3trigger/s3trigger_stack.py
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,35 @@ | ||
from aws_cdk import ( | ||
aws_lambda as _lambda, | ||
aws_s3 as _s3, | ||
aws_s3_notifications, | ||
aws_ecr as ecr, | ||
Stack | ||
) | ||
from constructs import Construct | ||
|
||
class S3TriggerStack(Stack): | ||
|
||
def __init__(self, scope: Construct, id: str, **kwargs) -> None: | ||
super().__init__(scope, id, **kwargs) | ||
|
||
# create lambda function | ||
#function = _lambda.Function(self, "lambda_function", | ||
#runtime=_lambda.Runtime.PYTHON_3_7, | ||
#handler="lambda-handler.main", | ||
#code=_lambda.Code.from_asset("./lambda")) | ||
#function=_lambda.DockerImageFunction(self, "ExagoLambdaFunction", | ||
#code=_lambda.DockerImageCode.from_image_asset("lambda")) | ||
ecr_repository = ecr.Repository(self, "ExagoRepo", | ||
repository_name="exago_repo") # Specify your repository name | ||
|
||
# Define the Lambda function using a Docker container from ECR | ||
function = _lambda.DockerImageFunction(self, "ExagoLambdaFunction", | ||
code=_lambda.DockerImageCode.from_ecr(repository=ecr_repository)) | ||
# create s3 bucket | ||
s3 = _s3.Bucket(self, "s3bucket") | ||
|
||
# create s3 notification for lambda function | ||
notification = aws_s3_notifications.LambdaDestination(function) | ||
|
||
# assign notification for the s3 event type (ex: OBJECT_CREATED) | ||
s3.add_event_notification(_s3.EventType.OBJECT_CREATED, notification) |