Skip to content

Commit 910be71

Browse files
authored
docs(tutorial): clarify connection methods for IdP and Auth_profile (#144)
* clarify connection methods for IdP and Auth_profile * improve tutorial
1 parent 1b0f134 commit 910be71

File tree

1 file changed

+30
-129
lines changed

1 file changed

+30
-129
lines changed

tutorials/001 - Connecting to Amazon Redshift.ipynb

Lines changed: 30 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
{
44
"cell_type": "markdown",
55
"metadata": {
6-
"collapsed": true,
7-
"pycharm": {
8-
"name": "#%% md\n"
9-
}
6+
"collapsed": true
107
},
118
"source": [
129
"# Connecting to Amazon Redshift"
@@ -22,11 +19,7 @@
2219
},
2320
{
2421
"cell_type": "markdown",
25-
"metadata": {
26-
"pycharm": {
27-
"name": "#%% md\n"
28-
}
29-
},
22+
"metadata": {},
3023
"source": [
3124
"## Using Database credentials\n",
3225
"Raw database credentials can be used for establishing a connection to an Amazon Redshift cluster. While straight forward, this approach lack the strong security and user access controls provides by Identity and access management (IAM) and identity provider (IdP) plugins."
@@ -35,11 +28,7 @@
3528
{
3629
"cell_type": "code",
3730
"execution_count": null,
38-
"metadata": {
39-
"pycharm": {
40-
"name": "#%%\n"
41-
}
42-
},
31+
"metadata": {},
4332
"outputs": [],
4433
"source": [
4534
"import redshift_connector\n",
@@ -79,11 +68,7 @@
7968
},
8069
{
8170
"cell_type": "markdown",
82-
"metadata": {
83-
"pycharm": {
84-
"name": "#%% md\n"
85-
}
86-
},
71+
"metadata": {},
8772
"source": [
8873
"## Using IAM Credentials\n",
8974
"IAM Credentials can be supplied directly to ``connect(...)`` using an AWS profile. This approach allows users the option of using temporary credentials and limiting the permissions the connected user has."
@@ -92,11 +77,7 @@
9277
{
9378
"cell_type": "code",
9479
"execution_count": null,
95-
"metadata": {
96-
"pycharm": {
97-
"name": "#%%\n"
98-
}
99-
},
80+
"metadata": {},
10081
"outputs": [],
10182
"source": [
10283
"import redshift_connector\n",
@@ -122,11 +103,7 @@
122103
},
123104
{
124105
"cell_type": "markdown",
125-
"metadata": {
126-
"pycharm": {
127-
"name": "#%% md\n"
128-
}
129-
},
106+
"metadata": {},
130107
"source": [
131108
"`~/.aws/credentials`\n",
132109
"```\n",
@@ -144,23 +121,15 @@
144121
},
145122
{
146123
"cell_type": "markdown",
147-
"metadata": {
148-
"pycharm": {
149-
"name": "#%% md\n"
150-
}
151-
},
124+
"metadata": {},
152125
"source": [
153126
"Alternatively, IAM credentials can be supplied directly to ``connect(...)`` using AWS credentials as shown below:"
154127
]
155128
},
156129
{
157130
"cell_type": "code",
158131
"execution_count": null,
159-
"metadata": {
160-
"pycharm": {
161-
"name": "#%%\n"
162-
}
163-
},
132+
"metadata": {},
164133
"outputs": [],
165134
"source": [
166135
"import redshift_connector\n",
@@ -182,11 +151,7 @@
182151
},
183152
{
184153
"cell_type": "markdown",
185-
"metadata": {
186-
"pycharm": {
187-
"name": "#%% md\n"
188-
}
189-
},
154+
"metadata": {},
190155
"source": [
191156
"# Connecting using an Amazon Redshift Authentication Profile\n",
192157
"An Amazon Redshift authentication profile can be used for authentication with Amazon Redshift via ``redshift_connector``. This approach allows connection properties to be stored in the server side and retrieved by ``redshift_connector``. Any connection parameter which appears in both the authentication profile and is directly provided to ``redshift_connector.connect(...)`` will be overriden by the value provided in the authentication profile.\n",
@@ -201,11 +166,7 @@
201166
{
202167
"cell_type": "code",
203168
"execution_count": null,
204-
"metadata": {
205-
"pycharm": {
206-
"name": "#%%\n"
207-
}
208-
},
169+
"metadata": {},
209170
"outputs": [],
210171
"source": [
211172
"import boto3\n",
@@ -221,7 +182,7 @@
221182
"}\n",
222183
"\n",
223184
"try:\n",
224-
" client = boto3.client(\"redshift\")\n",
185+
" client = boto3.client(\"redshift\", \"us-east-2\")\n",
225186
" client.create_authentication_profile(\n",
226187
" AuthenticationProfileName=\"QAProfile\",\n",
227188
" AuthenticationProfileContent=json.dumps(authentication_profile_contents)\n",
@@ -232,11 +193,7 @@
232193
},
233194
{
234195
"cell_type": "markdown",
235-
"metadata": {
236-
"pycharm": {
237-
"name": "#%% md\n"
238-
}
239-
},
196+
"metadata": {},
240197
"source": [
241198
"The Redshift authentication profile, named ``QAProfile`` has been created. This profile is intended for use by a QA team who would like to avoid hard-coded references to a specific cluster in their projects. Its contents are in JSON format and contain fields such as ``host`` and ``cluster_identifier``.\n",
242199
"\n",
@@ -246,11 +203,7 @@
246203
{
247204
"cell_type": "code",
248205
"execution_count": null,
249-
"metadata": {
250-
"pycharm": {
251-
"name": "#%%\n"
252-
}
253-
},
206+
"metadata": {},
254207
"outputs": [],
255208
"source": [
256209
"import redshift_connector\n",
@@ -270,13 +223,9 @@
270223
},
271224
{
272225
"cell_type": "markdown",
273-
"metadata": {
274-
"pycharm": {
275-
"name": "#%% md\n"
276-
}
277-
},
226+
"metadata": {},
278227
"source": [
279-
"Noting the ``region`` parameter above, we can see that while the Amazon Redshift authentication profile lives in ``us-west-2``, ``examplecluster`` lives in ``us-west-1``. When retrieving temporary IAM credentials to connect to this cluster, the ``region`` provided in the authentication profile will be used.\n",
228+
"Noting the ``region`` parameter above, we can see that while the Amazon Redshift authentication profile lives in ``us-west-2``, ``examplecluster`` lives in ``us-west-1``. When retrieving temporary IAM credentials to connect to this cluster, provide the ``region`` where the Redshift authentication profile lives and not the region of the cluster. ``region`` provided above is the region where the authentication profile is created as shown in `` client = boto3.client(\"redshift\", \"us-east-2\")``.\n",
280229
"\n",
281230
"Please see the ``redshift_connector.RedshiftProperty`` class for guidance on how to define the key and value contents of the JSON authentication profile contents.\n",
282231
"\n",
@@ -286,11 +235,7 @@
286235
{
287236
"cell_type": "code",
288237
"execution_count": null,
289-
"metadata": {
290-
"pycharm": {
291-
"name": "#%%\n"
292-
}
293-
},
238+
"metadata": {},
294239
"outputs": [],
295240
"source": [
296241
"try:\n",
@@ -313,23 +258,15 @@
313258
},
314259
{
315260
"cell_type": "markdown",
316-
"metadata": {
317-
"pycharm": {
318-
"name": "#%% md\n"
319-
}
320-
},
261+
"metadata": {},
321262
"source": [
322263
"## Authenticating using Active Directory Federation Service (ADFS) identity provider plugin"
323264
]
324265
},
325266
{
326267
"cell_type": "code",
327268
"execution_count": null,
328-
"metadata": {
329-
"pycharm": {
330-
"name": "#%%\n"
331-
}
332-
},
269+
"metadata": {},
333270
"outputs": [],
334271
"source": [
335272
"import redshift_connector\n",
@@ -348,11 +285,7 @@
348285
},
349286
{
350287
"cell_type": "markdown",
351-
"metadata": {
352-
"pycharm": {
353-
"name": "#%% md\n"
354-
}
355-
},
288+
"metadata": {},
356289
"source": [
357290
"## Authenticating using Azure identity provider plugin\n",
358291
"Values for `client_id`, `client_secret` can be created and found within the Enterprise Application created with Azure."
@@ -361,18 +294,15 @@
361294
{
362295
"cell_type": "code",
363296
"execution_count": null,
364-
"metadata": {
365-
"pycharm": {
366-
"name": "#%%\n"
367-
}
368-
},
297+
"metadata": {},
369298
"outputs": [],
370299
"source": [
371300
"import redshift_connector\n",
372301
"\n",
373302
"conn: redshift_connector.Connection = redshift_connector.connect(\n",
374303
" iam=True,\n",
375304
" database='dev',\n",
305+
" region='us-east-1',\n",
376306
" cluster_identifier='my-testing-cluster',\n",
377307
" credentials_provider='AzureCredentialsProvider',\n",
378308
" user='brooke@myazure.org',\n",
@@ -386,23 +316,15 @@
386316
},
387317
{
388318
"cell_type": "markdown",
389-
"metadata": {
390-
"pycharm": {
391-
"name": "#%% md\n"
392-
}
393-
},
319+
"metadata": {},
394320
"source": [
395321
"## Authenticating using Azure Browser identity provider plugin"
396322
]
397323
},
398324
{
399325
"cell_type": "code",
400326
"execution_count": null,
401-
"metadata": {
402-
"pycharm": {
403-
"name": "#%%\n"
404-
}
405-
},
327+
"metadata": {},
406328
"outputs": [],
407329
"source": [
408330
"import redshift_connector\n",
@@ -421,11 +343,7 @@
421343
},
422344
{
423345
"cell_type": "markdown",
424-
"metadata": {
425-
"pycharm": {
426-
"name": "#%% md\n"
427-
}
428-
},
346+
"metadata": {},
429347
"source": [
430348
"## Authenticating using Okta identity provider plugin\n",
431349
"Values for `idp_host`, `app_id`, and `app_name` can be located within the Okta application created."
@@ -434,18 +352,15 @@
434352
{
435353
"cell_type": "code",
436354
"execution_count": null,
437-
"metadata": {
438-
"pycharm": {
439-
"name": "#%%\n"
440-
}
441-
},
355+
"metadata": {},
442356
"outputs": [],
443357
"source": [
444358
"import redshift_connector\n",
445359
"\n",
446360
"conn: redshift_connector.Connection = redshift_connector.connect(\n",
447361
" iam=True,\n",
448362
" database='dev',\n",
363+
" region='us-east-1',\n",
449364
" cluster_identifier='my-testing-cluster',\n",
450365
" credentials_provider='OktaCredentialsProvider',\n",
451366
" user='brooke@myazure.org',\n",
@@ -458,23 +373,15 @@
458373
},
459374
{
460375
"cell_type": "markdown",
461-
"metadata": {
462-
"pycharm": {
463-
"name": "#%% md\n"
464-
}
465-
},
376+
"metadata": {},
466377
"source": [
467378
"## Authenticating using JumpCloud via generic Saml Browser identity provider plugin"
468379
]
469380
},
470381
{
471382
"cell_type": "code",
472383
"execution_count": null,
473-
"metadata": {
474-
"pycharm": {
475-
"name": "#%%\n"
476-
}
477-
},
384+
"metadata": {},
478385
"outputs": [],
479386
"source": [
480387
"import redshift_connector\n",
@@ -521,10 +428,7 @@
521428
" pass"
522429
],
523430
"metadata": {
524-
"collapsed": false,
525-
"pycharm": {
526-
"name": "#%%\n"
527-
}
431+
"collapsed": false
528432
}
529433
},
530434
{
@@ -557,10 +461,7 @@
557461
" pass\n"
558462
],
559463
"metadata": {
560-
"collapsed": false,
561-
"pycharm": {
562-
"name": "#%%\n"
563-
}
464+
"collapsed": false
564465
}
565466
}
566467
],

0 commit comments

Comments
 (0)