in configurations/RedshiftConfigTestingLambda.py [0:0]
def create_cluster(client, cluster_identifier, snapshot_id, redshift_iam_role, parameter_group_name, subnet_group,
security_group_id, snapshot_account_id, node_type, number_of_nodes, master_user_name, database_name,
port, publicly_accessible, secrets_manager_arn):
try:
if snapshot_id is None or snapshot_id == "N/A":
master_user_secret = json.loads(
boto3.client('secretsmanager').get_secret_value(SecretId=secrets_manager_arn).get('SecretString'))
master_user_password = master_user_secret.get('password')
client.create_cluster(DBName=database_name,
ClusterIdentifier=cluster_identifier,
ClusterType='single-node' if int(number_of_nodes) == 1 else 'multi-node',
NodeType=node_type,
MasterUsername=master_user_name,
MasterUserPassword=master_user_password,
VpcSecurityGroupIds=[security_group_id],
ClusterSubnetGroupName=subnet_group,
ClusterParameterGroupName=parameter_group_name,
Port=port,
NumberOfNodes=int(number_of_nodes),
PubliclyAccessible=publicly_accessible,
IamRoles=[redshift_iam_role])
else:
if snapshot_account_id is None or snapshot_account_id == "N/A":
snapshot_account_id = boto3.client('sts').get_caller_identity()['Account']
client.restore_from_cluster_snapshot(NumberOfNodes=int(number_of_nodes),
NodeType=node_type,
ClusterIdentifier=cluster_identifier,
SnapshotIdentifier=snapshot_id,
OwnerAccount=snapshot_account_id,
Port=port,
ClusterSubnetGroupName=subnet_group,
PubliclyAccessible=publicly_accessible,
ClusterParameterGroupName=parameter_group_name,
VpcSecurityGroupIds=[security_group_id],
IamRoles=[redshift_iam_role])
status = 'Initiated'
except be.ClientError as e:
msg = e.response['Error']['Code']
if msg == 'ClusterAlreadyExists':
status = msg
elif msg == 'InvalidParameterValue':
source_node_type, source_number_of_nodes = get_source_cluster_config(client, snapshot_id)
client.restore_from_cluster_snapshot(NumberOfNodes=source_number_of_nodes,
NodeType=source_node_type,
ClusterIdentifier=cluster_identifier,
SnapshotIdentifier=snapshot_id,
OwnerAccount=snapshot_account_id,
Port=port,
ClusterSubnetGroupName=subnet_group,
PubliclyAccessible=publicly_accessible,
ClusterParameterGroupName=parameter_group_name,
VpcSecurityGroupIds=[security_group_id],
IamRoles=[redshift_iam_role])
status = 'NeedClassicResize'
else:
raise
return status