|
381 | 381 | },
|
382 | 382 | {
|
383 | 383 | "cell_type": "code",
|
384 |
| - "execution_count": 62, |
| 384 | + "execution_count": 66, |
385 | 385 | "metadata": {},
|
386 | 386 | "outputs": [
|
387 | 387 | {
|
|
432 | 432 | " 'AquaConfigurationStatus': 'auto'}}"
|
433 | 433 | ]
|
434 | 434 | },
|
435 |
| - "execution_count": 62, |
| 435 | + "execution_count": 66, |
436 | 436 | "metadata": {},
|
437 | 437 | "output_type": "execute_result"
|
438 | 438 | }
|
|
444 | 444 | },
|
445 | 445 | {
|
446 | 446 | "cell_type": "code",
|
447 |
| - "execution_count": 63, |
| 447 | + "execution_count": 67, |
448 | 448 | "metadata": {},
|
449 | 449 | "outputs": [
|
450 | 450 | {
|
|
503 | 503 | " <td>Endpoint</td>\n",
|
504 | 504 | " <td>{'Address': 'my-first-redshift.cwdmvcljvlpf.us-east-2.redshift.amazonaws.com', 'Port': 5439}</td>\n",
|
505 | 505 | " </tr>\n",
|
| 506 | + " <tr>\n", |
| 507 | + " <th>6</th>\n", |
| 508 | + " <td>VpcId</td>\n", |
| 509 | + " <td>vpc-0343be62f9b6090eb</td>\n", |
| 510 | + " </tr>\n", |
506 | 511 | " </tbody>\n",
|
507 | 512 | "</table>\n",
|
508 | 513 | "</div>"
|
|
515 | 520 | "3 MasterUsername \n",
|
516 | 521 | "4 DBName \n",
|
517 | 522 | "5 Endpoint \n",
|
| 523 | + "6 VpcId \n", |
518 | 524 | "\n",
|
519 | 525 | " value \n",
|
520 | 526 | "0 my-first-redshift \n",
|
521 | 527 | "1 dc2.large \n",
|
522 | 528 | "2 available \n",
|
523 | 529 | "3 awsuser \n",
|
524 | 530 | "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 " |
526 | 533 | ]
|
527 | 534 | },
|
528 |
| - "execution_count": 63, |
| 535 | + "execution_count": 67, |
529 | 536 | "metadata": {},
|
530 | 537 | "output_type": "execute_result"
|
531 | 538 | }
|
532 | 539 | ],
|
533 | 540 | "source": [
|
534 | 541 | "def prettyRedshiftProps(props):\n",
|
535 | 542 | " 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", |
537 | 544 | " x = [(k, v) for k,v in props.items() if k in keysToShow]\n",
|
538 | 545 | " return pd.DataFrame(data=x, columns=['key', 'value'])\n",
|
539 | 546 | " \n",
|
540 | 547 | "prettyRedshiftProps(cluster_details)"
|
541 | 548 | ]
|
542 | 549 | },
|
| 550 | + { |
| 551 | + "attachments": {}, |
| 552 | + "cell_type": "markdown", |
| 553 | + "metadata": {}, |
| 554 | + "source": [ |
| 555 | + "ATTACH VPC TO THE REDSHIFT CLUSTER USING ec2 CONNECTION" |
| 556 | + ] |
| 557 | + }, |
543 | 558 | {
|
544 | 559 | "cell_type": "code",
|
545 |
| - "execution_count": null, |
| 560 | + "execution_count": 78, |
546 | 561 | "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 | + ] |
549 | 590 | },
|
550 | 591 | {
|
551 | 592 | "cell_type": "code",
|
|
0 commit comments