11import json
2+ import os
23import sys
34import time
45import boto3
78# sample-data/customers.jsonl into SQS.
89
910# For live AWS, can set these to other values.
10- AWS_PROFILE_NAME = 'localstack'
11+ AWS_PROFILE = 'localstack'
1112Q_URL = 'http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/sqs-senzing-local-ingest'
13+ S3_BUCKET_NAME = 'sqs-senzing-local-export'
1214
1315#------------------------------------------------------------------------------
1416
@@ -23,7 +25,9 @@ def make_boto_session(fpath=None):
2325 if fpath :
2426 return boto3 .Session (** json .load (open (fpath )))
2527 else :
26- return boto3 .Session (profile_name = AWS_PROFILE_NAME )
28+ # Here we pass in profile_name explicitly since it's not necessarily an env
29+ # var in this context.
30+ return boto3 .Session (profile_name = AWS_PROFILE )
2731
2832def make_sqs_client (boto_session ):
2933 return boto_session .client ('sqs' )
@@ -71,3 +75,25 @@ def _get_1_msg(sqs, q_url):
7175 print (resp )
7276 return resp
7377
78+ #-------------------------------------------------------------------------------
79+
80+ def make_s3_client ():
81+ try :
82+ # Here we pass in profile_name explicitly since it's not necessarily an env
83+ # var in this context.
84+ sess = boto3 .Session (profile_name = AWS_PROFILE )
85+ if 'AWS_ENDPOINT_URL' in os .environ :
86+ return sess .client ('s3' , endpoint_url = os .environ ['AWS_ENDPOINT_URL' ])
87+ else :
88+ return sess .client ('s3' )
89+ except Exception as e :
90+ print (e )
91+
92+ def upload_test_file_to_s3 ():
93+ print ("Starting test upload to S3 ..." )
94+ s3 = make_s3_client ()
95+ print (s3 )
96+ fname = 'sample-data/hemingway.txt'
97+ resp = s3 .upload_file (fname , S3_BUCKET_NAME , fname [fname .rfind ('/' )+ 1 :])
98+ print (resp )
99+ print ('Upload successful.' )
0 commit comments