12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
14
15
+ import ast
15
16
import sys
16
17
17
18
import click
19
+ import lightning_cloud
18
20
import rich
19
21
from rich .live import Live
20
22
from rich .spinner import Spinner
29
31
30
32
31
33
@click .argument ("name" , required = True )
32
- @click .argument ("region" , required = True )
33
- @click .argument ("source" , required = True )
34
- @click .argument ("destination" , required = False )
35
- @click .argument ("project_name" , required = False )
34
+ @click .option ("--region" , help = "The AWS region of your bucket. Example: `us-west-1`." , required = True )
35
+ @click .option (
36
+ "--source" , help = "The URL path to your AWS S3 folder. Example: `s3://pl-flash-data/images/`." , required = True
37
+ )
38
+ @click .option (
39
+ "--secret_arn_name" ,
40
+ help = "The name of role stored as a secret on Lightning AI to access your data. "
41
+ "Learn more with https://gist.github.com/tchaton/12ad4b788012e83c0eb35e6223ae09fc. "
42
+ "Example: `my_role`." ,
43
+ required = False ,
44
+ )
45
+ @click .option (
46
+ "--destination" , help = "Where your data should appear in the cloud. Currently not supported." , required = False
47
+ )
48
+ @click .option ("--project_name" , help = "The project name on which to create the data connection." , required = False )
36
49
def connect_data (
37
50
name : str ,
38
51
region : str ,
39
52
source : str ,
53
+ secret_arn_name : str = "" ,
40
54
destination : str = "" ,
41
55
project_name : str = "" ,
42
56
) -> None :
43
57
"""Create a new data connection."""
44
58
45
- from lightning_cloud .openapi import ProjectIdDataConnectionsBody
59
+ from lightning_cloud .openapi import Create , V1AwsDataConnection
46
60
47
61
if sys .platform == "win32" :
48
62
_error_and_exit ("Data connection isn't supported on windows. Open an issue on Github." )
@@ -51,7 +65,7 @@ def connect_data(
51
65
52
66
live .stop ()
53
67
54
- client = LightningClient ()
68
+ client = LightningClient (retry = False )
55
69
projects = client .projects_service_list_memberships ()
56
70
57
71
project_id = None
@@ -71,12 +85,15 @@ def connect_data(
71
85
)
72
86
73
87
try :
74
- _ = client .data_connection_service_create_data_connection (
75
- body = ProjectIdDataConnectionsBody (
88
+ client .data_connection_service_create_data_connection (
89
+ body = Create (
76
90
name = name ,
77
- region = region ,
78
- source = source ,
79
- destination = destination ,
91
+ aws = V1AwsDataConnection (
92
+ region = region ,
93
+ source = source ,
94
+ destination = destination ,
95
+ secret_arn_name = secret_arn_name ,
96
+ ),
80
97
),
81
98
project_id = project_id ,
82
99
)
@@ -86,8 +103,8 @@ def connect_data(
86
103
# project_id=project_id,
87
104
# id=response.id,
88
105
# )
89
- # print(response)
90
- except Exception :
91
- _error_and_exit ("The data connection creation failed." )
106
+ except lightning_cloud . openapi . rest . ApiException as e :
107
+ message = ast . literal_eval ( e . body . decode ( "utf-8" ))[ "message" ]
108
+ _error_and_exit (f "The data connection creation failed. Message: { message } " )
92
109
93
110
rich .print (f"[green]Succeeded[/green]: You have created a new data connection { name } ." )
0 commit comments