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
lb1 = lambda_alpha_.PythonFunction(self, f"{resource_prefix}-function", | |
entry="./rds_lambda", | |
index="rds_lambda.py", | |
handler="lambda_handler", | |
runtime=_lambda.Runtime.PYTHON_3_9, | |
vpc=vpc, | |
vpc_subnets=ec2.SubnetSelection( | |
subnet_type=ec2.SubnetType.PRIVATE_WITH_NAT | |
), | |
security_groups=[ |
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
bastion_host = ec2.Instance(self, id=f'{resource_prefix}-bastion-host', | |
instance_type=ec2.InstanceType(instance_type_identifier='t2.micro'), | |
machine_image=ec2.AmazonLinuxImage( | |
edition=ec2.AmazonLinuxEdition.STANDARD, | |
generation=ec2.AmazonLinuxGeneration.AMAZON_LINUX_2, | |
virtualization=ec2.AmazonLinuxVirt.HVM, | |
storage=ec2.AmazonLinuxStorage.GENERAL_PURPOSE | |
), | |
vpc=vpc, | |
key_name='pryan-aws', # must create the key name manually first |
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
rds_instance = rds.DatabaseInstance(self, | |
id=f'{resource_prefix}-DBInstance', | |
engine=rds.DatabaseInstanceEngine.mysql( | |
version=rds.MysqlEngineVersion.VER_8_0_16), | |
credentials=rds.Credentials.from_secret(db_credentials_secret), | |
instance_type= | |
ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.MICRO), | |
vpc=vpc, | |
vpc_subnets=ec2.SubnetSelection( | |
subnet_type=ec2.SubnetType.PRIVATE_ISOLATED |
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
secrets_template = json.dumps({ | |
"username": f'{db_username}' | |
}) | |
db_credentials_secret = secrets.Secret(self, id=f'{resource_prefix}-DBCredentialsSecret', | |
secret_name=construct_id + '-rds-credentials', | |
generate_secret_string=secrets.SecretStringGenerator( | |
secret_string_template=secrets_template, | |
exclude_punctuation=True, | |
include_space=False, | |
generate_string_key="password" |
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
lambda_to_proxy_sg = ec2.SecurityGroup(self, id=f'{resource_prefix}-l2proxy-sg', | |
vpc=vpc, | |
allow_all_outbound=True, | |
description="Lambda to RDS Proxy Connection" | |
) | |
bastion_sg = ec2.SecurityGroup(self, id='bastionsg', | |
security_group_name=f'{resource_prefix}-cdk-bastion-sg', | |
vpc=vpc, | |
description=f'{resource_prefix} SG for Bastion', | |
allow_all_outbound=True) |
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
vpc = ec2.Vpc(self, f'{resource_prefix}-Vpc', | |
cidr='10.40.0.0/16', | |
nat_gateways=1, | |
max_azs=2, | |
enable_dns_hostnames=True, | |
enable_dns_support=True, | |
subnet_configuration=[ | |
ec2.SubnetConfiguration( | |
name=f"{resource_prefix}-Public-subnet", | |
subnet_type=ec2.SubnetType.PUBLIC, |
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
import json | |
import logging | |
import os | |
import pandas as pd | |
import joblib | |
logger = logging.getLogger() | |
logger.setLevel(logging.DEBUG) | |
mount_dir = "/mnt/model" |
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
api = api_gw.HttpApi(self, f'{resources_prefix}-Test API Lambda', | |
default_integration=integrations.HttpLambdaIntegration(id="lb1-lambda-proxy", | |
handler=lb1) | |
) |
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
lb1 = lambda_alpha_.PythonFunction(self, f"{resources_prefix}-heartfailure-function", | |
entry="./ml_lambda", | |
index="heart_failure_lambda.py", | |
handler="lambda_handler", | |
runtime=_lambda.Runtime.PYTHON_3_7, | |
vpc=self.vpc, | |
security_groups=[ | |
self.efs_access_sg | |
], | |
timeout=Duration.seconds(300), |
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
fs = efs.FileSystem(self, f'{resources_prefix}-FileSystem', | |
vpc=self.vpc, | |
security_group=self.efs_access_sg, | |
removal_policy=RemovalPolicy.DESTROY) | |
access_point = fs.add_access_point(f'{resources_prefix}-LambdaAccessPoint', | |
create_acl=efs.Acl(owner_gid='1000', owner_uid='1000', permissions='755'), | |
path="/export/lambda", | |
posix_user=efs.PosixUser(gid="1000", uid="1000")) |