Skip to content

Commit e09b391

Browse files
vpc attached - set for load
1 parent feecb3f commit e09b391

File tree

1 file changed

+50
-9
lines changed

1 file changed

+50
-9
lines changed

notebooks/redshift_warehousing.ipynb

+50-9
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@
381381
},
382382
{
383383
"cell_type": "code",
384-
"execution_count": 62,
384+
"execution_count": 66,
385385
"metadata": {},
386386
"outputs": [
387387
{
@@ -432,7 +432,7 @@
432432
" 'AquaConfigurationStatus': 'auto'}}"
433433
]
434434
},
435-
"execution_count": 62,
435+
"execution_count": 66,
436436
"metadata": {},
437437
"output_type": "execute_result"
438438
}
@@ -444,7 +444,7 @@
444444
},
445445
{
446446
"cell_type": "code",
447-
"execution_count": 63,
447+
"execution_count": 67,
448448
"metadata": {},
449449
"outputs": [
450450
{
@@ -503,6 +503,11 @@
503503
" <td>Endpoint</td>\n",
504504
" <td>{'Address': 'my-first-redshift.cwdmvcljvlpf.us-east-2.redshift.amazonaws.com', 'Port': 5439}</td>\n",
505505
" </tr>\n",
506+
" <tr>\n",
507+
" <th>6</th>\n",
508+
" <td>VpcId</td>\n",
509+
" <td>vpc-0343be62f9b6090eb</td>\n",
510+
" </tr>\n",
506511
" </tbody>\n",
507512
"</table>\n",
508513
"</div>"
@@ -515,37 +520,73 @@
515520
"3 MasterUsername \n",
516521
"4 DBName \n",
517522
"5 Endpoint \n",
523+
"6 VpcId \n",
518524
"\n",
519525
" value \n",
520526
"0 my-first-redshift \n",
521527
"1 dc2.large \n",
522528
"2 available \n",
523529
"3 awsuser \n",
524530
"4 first-redshift-db \n",
525-
"5 {'Address': 'my-first-redshift.cwdmvcljvlpf.us-east-2.redshift.amazonaws.com', 'Port': 5439} "
531+
"5 {'Address': 'my-first-redshift.cwdmvcljvlpf.us-east-2.redshift.amazonaws.com', 'Port': 5439} \n",
532+
"6 vpc-0343be62f9b6090eb "
526533
]
527534
},
528-
"execution_count": 63,
535+
"execution_count": 67,
529536
"metadata": {},
530537
"output_type": "execute_result"
531538
}
532539
],
533540
"source": [
534541
"def prettyRedshiftProps(props):\n",
535542
" pd.set_option('display.max_colwidth', None)\n",
536-
" keysToShow = ['ClusterIdentifier', 'NodeType', 'ClusterStatus', 'MasterUsername', 'DBName', 'Endpoint', 'ClusterStatus']\n",
543+
" keysToShow = ['ClusterIdentifier', 'NodeType', 'ClusterStatus', 'MasterUsername', 'DBName', 'Endpoint', 'ClusterStatus', 'VpcId']\n",
537544
" x = [(k, v) for k,v in props.items() if k in keysToShow]\n",
538545
" return pd.DataFrame(data=x, columns=['key', 'value'])\n",
539546
" \n",
540547
"prettyRedshiftProps(cluster_details)"
541548
]
542549
},
550+
{
551+
"attachments": {},
552+
"cell_type": "markdown",
553+
"metadata": {},
554+
"source": [
555+
"ATTACH VPC TO THE REDSHIFT CLUSTER USING ec2 CONNECTION"
556+
]
557+
},
543558
{
544559
"cell_type": "code",
545-
"execution_count": null,
560+
"execution_count": 78,
546561
"metadata": {},
547-
"outputs": [],
548-
"source": []
562+
"outputs": [
563+
{
564+
"name": "stdout",
565+
"output_type": "stream",
566+
"text": [
567+
"An error occurred (InvalidPermission.Duplicate) when calling the AuthorizeSecurityGroupIngress operation: the specified rule \"peer: 0.0.0.0/0, TCP, from port: 5439, to port: 5439, ALLOW\" already exists\n"
568+
]
569+
}
570+
],
571+
"source": [
572+
"try:\n",
573+
" vpc = ec2.Vpc(id=cluster_details['VpcId'])\n",
574+
" defaultSG = list(vpc.security_groups.all())[0]\n",
575+
"\n",
576+
" defaultSG.authorize_ingress(\n",
577+
" CidrIp='0.0.0.0/0',\n",
578+
" IpProtocol='TCP',\n",
579+
" FromPort=int(DWH_PORT),\n",
580+
" ToPort=int(DWH_PORT),\n",
581+
" GroupName=defaultSG.group_name\n",
582+
" )\n",
583+
"\n",
584+
" print(\"VPC Attached to Redshift through ec2\")\n",
585+
"\n",
586+
"\n",
587+
"except Exception as e:\n",
588+
" print(e)"
589+
]
549590
},
550591
{
551592
"cell_type": "code",

0 commit comments

Comments
 (0)