From 9ec1fd968cadaecfbf8294ab4611bfb28a5bc83e Mon Sep 17 00:00:00 2001 From: Imtiah01 Date: Fri, 17 Jan 2025 22:47:16 +0000 Subject: [PATCH] refactor --- app.py | 2 +- cdp_cdk_python/redshift_role_policy_stack.py | 62 +++++++++----------- requirements.txt | 4 +- 3 files changed, 32 insertions(+), 36 deletions(-) diff --git a/app.py b/app.py index b6e7f1b..7968459 100644 --- a/app.py +++ b/app.py @@ -11,7 +11,7 @@ app = cdk.App() LambdaRolePolicyStack(app, "LambdaRolePolicyStack") -# RedshiftRolePolicyStack(app, "RedshiftRolePolicyStack") +RedshiftRolePolicyStack(app, "RedshiftRolePolicyStack") # If you don't specify 'env', this stack will be environment-agnostic. # Account/Region-dependent features and context lookups will not work, diff --git a/cdp_cdk_python/redshift_role_policy_stack.py b/cdp_cdk_python/redshift_role_policy_stack.py index 24fcf7c..0fdd3ee 100644 --- a/cdp_cdk_python/redshift_role_policy_stack.py +++ b/cdp_cdk_python/redshift_role_policy_stack.py @@ -5,8 +5,7 @@ aws_s3 as s3, aws_iam as iam, aws_lambda as _lambda, - # aws_redshiftserverless as redshiftserverless, - + aws_redshiftserverless as redshiftserverless ) import aws_cdk as core from constructs import Construct @@ -14,7 +13,7 @@ import os import json from aws_cdk.cloudformation_include import CfnInclude - +from aws_cdk.aws_redshift import class RedshiftRolePolicyStack(Stack): def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None: @@ -80,37 +79,37 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None: ) ) - # # Create Redshift Serverless Namespace - # namespace = redshiftserverless.CfnNamespace( - # self, "RedshiftNamespace", - # namespace_name="my-redshift-namespace", - # admin_username="admin", - # admin_user_password="YourSecurePassword123!", # Use Secrets Manager for production - # iam_roles=[redshift_role.role_arn] - # ) + # Create Redshift Serverless Namespace + namespace = redshiftserverless.CfnNamespace( + self, "RedshiftNamespace", + namespace_name="my-redshift-namespace", + admin_username="admin", + admin_user_password="YourSecurePassword123!", # Use Secrets Manager for production + iam_roles=[redshift_role.role_arn] + ) - # # Create Redshift Serverless Workgroup - # workgroup = redshiftserverless.CfnWorkgroup( - # self, "RedshiftWorkgroup", - # workgroup_name="my-redshift-workgroup", - # namespace_name=namespace.namespace_name, - # base_capacity=32, # Base capacity in Redshift Processing Units (RPUs) - # publicly_accessible=True, - # subnet_ids=["subnet-xxxxxxx", "subnet-yyyyyyy"], # Replace with actual subnet IDs - # security_group_ids=["sg-zzzzzzzz"] # Replace with actual security group IDs - # ) + # Create Redshift Serverless Workgroup + workgroup = redshiftserverless.CfnWorkgroup( + self, "RedshiftWorkgroup", + workgroup_name="my-redshift-workgroup", + namespace_name=namespace.namespace_name, + base_capacity=32, # Base capacity in Redshift Processing Units (RPUs) + publicly_accessible=True, + subnet_ids=["subnet-xxxxxxx", "subnet-yyyyyyy"], # Replace with actual subnet IDs + security_group_ids=["sg-zzzzzzzz"] # Replace with actual security group IDs + ) - print('lambda path: %s' % os.path.join(dirname, "./mle-non-pii-redshift-role-template.json")) - print('lambda path: %s' % os.path.join(dirname, "lambda_function.py.zip")) - print('cwd: %s' % cwd) - - # core.CfnOutput( - # self, - # "WorkgroupEndpoint", - # value=workgroup.attr_endpoint_address) + core.CfnOutput( + self, + "WorkgroupEndpoint", + value=namespace.namespace_name) + core.CfnOutput( + self, + "WorkgroupEndpoint", + value=workgroup.attr_endpoint_address) core.CfnOutput( self, "RoleArn1", @@ -119,7 +118,4 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None: self, "RoleArn2", value=redshift_role.role_arn) - core.CfnOutput( - self, - "FunctionArn", - value=fn.function_arn) + diff --git a/requirements.txt b/requirements.txt index 1ebe890..1cd9244 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ attrs -aws-cdk-lib==2.18.0 -aws-cdk.cloud-assembly-schema==2.23.0 +aws-cdk-lib==2.176.0 +# aws-cdk.cloud-assembly-schema==2.23.0 boto3==1.23.10 botocore==1.26.10