diff --git a/api/.chalice/config.json b/api/.chalice/config.json index 1b0560766..3b2960416 100644 --- a/api/.chalice/config.json +++ b/api/.chalice/config.json @@ -31,7 +31,7 @@ "sessions_bucket": "mobs", "sessions_region": "us-east-1", "put_S3_TTL": "20", - "sourcemaps_reader": "http://127.0.0.1:3000/staging", + "sourcemaps_reader": "http://127.0.0.1:3000/", "sourcemaps_bucket": "sourcemaps", "sourcemaps_bucket_key": "", "sourcemaps_bucket_secret": "", diff --git a/api/chalicelib/utils/s3.py b/api/chalicelib/utils/s3.py index 06e308d38..49b6cfc85 100644 --- a/api/chalicelib/utils/s3.py +++ b/api/chalicelib/utils/s3.py @@ -2,11 +2,10 @@ from botocore.exceptions import ClientError from chalicelib.utils.helper import environ import boto3 - +import botocore from botocore.client import Config -# client = boto3.client('s3', endpoint_url=environ["S3_HOST"], -client = boto3.client('s3', endpoint_url="http://minio.db.svc.cluster.local:9000", +client = boto3.client('s3', endpoint_url=environ["S3_HOST"], aws_access_key_id=environ["S3_KEY"], aws_secret_access_key=environ["S3_SECRET"], config=Config(signature_version='s3v4'), @@ -14,14 +13,20 @@ client = boto3.client('s3', endpoint_url="http://minio.db.svc.cluster.local:9000 def exists(bucket, key): - response = client.list_objects_v2( - Bucket=bucket, - Prefix=key, - ) - for obj in response.get('Contents', []): - if obj['Key'] == key: - return True - return False + try: + boto3.resource('s3', endpoint_url=environ["S3_HOST"], + aws_access_key_id=environ["S3_KEY"], + aws_secret_access_key=environ["S3_SECRET"], + config=Config(signature_version='s3v4'), + region_name='us-east-1') \ + .Object(bucket, key).load() + except botocore.exceptions.ClientError as e: + if e.response['Error']['Code'] == "404": + return False + else: + # Something else has gone wrong. + raise + return True def get_presigned_url_for_sharing(bucket, expires_in, key, check_exists=False):