Skip to content

Commit dd24621

Browse files
authored
Update README.md (chimpler#14)
* Update README.md * Support object lambda
1 parent 70afb5d commit dd24621

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ In order to support development either on RDS or locally, we implemented our own
66
the one provided in RDS. It was implemented in Python using the boto3 library.
77

88
## Installation
9-
Make sure boto3 is installed using the default Python 2 installed on your computer.
9+
Make sure boto3 is installed using the default Python 3 installed on your computer.
1010
On MacOS, this can be done as follows:
1111

1212
sudo /usr/bin/easy_install boto3
@@ -35,7 +35,7 @@ Then install `postgres-aws-s3`:
3535

3636
Finally in Postgres:
3737
```postgresql
38-
psql> CREATE EXTENSION plpythonu;
38+
psql> CREATE EXTENSION plpython3u;
3939
psql> CREATE EXTENSION aws_s3;
4040
```
4141

@@ -395,7 +395,7 @@ psql> CREATE EXTENSION aws_s3;
395395
Set the endpoint url and the aws keys to use s3 (in localstack you can set the aws creds to any non-empty string):
396396
```
397397
psql> SET aws_s3.endpoint_url TO 'http://localstack:4566';
398-
psql> SET aws_s3.s3.aws_access_key_id TO 'dummy';
398+
psql> SET aws_s3.aws_access_key_id TO 'dummy';
399399
psql> SET aws_s3.secret_access_key TO 'dummy';
400400
```
401401

aws_s3--0.0.1.sql

+9-8
Original file line numberDiff line numberDiff line change
@@ -82,24 +82,25 @@ AS $$
8282
'endpoint_url': endpoint_url if endpoint_url else default_aws_settings.get('endpoint_url')
8383
}
8484

85-
s3 = boto3.client(
85+
s3 = boto3.resource(
8686
's3',
8787
region_name=region,
8888
**aws_settings
8989
)
9090

91-
response = s3.head_object(Bucket=bucket, Key=file_path)
91+
obj = s3.Object(bucket, file_path)
92+
response = obj.get()
9293
content_encoding = response.get('ContentEncoding')
94+
body = response['Body']
9395

9496
with tempfile.NamedTemporaryFile() as fd:
9597
if content_encoding and content_encoding.lower() == 'gzip':
96-
with tempfile.NamedTemporaryFile() as gzfd:
97-
s3.download_fileobj(bucket, file_path, gzfd)
98-
gzfd.flush()
99-
gzfd.seek(0)
100-
shutil.copyfileobj(gzip.GzipFile(fileobj=gzfd, mode='rb'), fd)
98+
with gzip.GzipFile(fileobj=body) as gzipfile:
99+
while fd.write(gzipfile.read(204800)):
100+
pass
101101
else:
102-
s3.download_fileobj(bucket, file_path, fd)
102+
while fd.write(body.read(204800)):
103+
pass
103104
fd.flush()
104105
formatted_column_list = "({column_list})".format(column_list=column_list) if column_list else ''
105106
res = plpy.execute("COPY {table_name} {formatted_column_list} FROM {filename} {options};".format(

0 commit comments

Comments
 (0)