How to use generate_presigned_url method in localstack

Best Python code snippet using localstack_python

uploadToS3.py

Source:uploadToS3.py Github

copy

Full Screen

...39 print("Could not upload local file to s3")40 print(error)41 exit(-1)42 try:43 response.append(s3.generate_presigned_url('get_object', Params={'Bucket': bucket, 'Key': remote_file}, ExpiresIn=(60*60*24*1)))44 response.append(s3.generate_presigned_url('get_object', Params={'Bucket': bucket, 'Key': remote_file},45 ExpiresIn=(60 * 60 * 24 * 2)))46 response.append(s3.generate_presigned_url('get_object', Params={'Bucket': bucket, 'Key': remote_file},47 ExpiresIn=(60 * 60 * 24 * 3)))48 response.append(s3.generate_presigned_url('get_object', Params={'Bucket': bucket, 'Key': remote_file},49 ExpiresIn=(60 * 60 * 24 * 4)))50 response.append(s3.generate_presigned_url('get_object', Params={'Bucket': bucket, 'Key': remote_file},51 ExpiresIn=(60 * 60 * 24 * 5)))52 response.append(s3.generate_presigned_url('get_object', Params={'Bucket': bucket, 'Key': remote_file},53 ExpiresIn=(60 * 60 * 24 * 6)))54 response.append(s3.generate_presigned_url('get_object', Params={'Bucket': bucket,'Key': remote_file}, ExpiresIn=604800))55 except ClientError as e:56 logging.error(e)57 return None58 return response59def get_file_path():60 parser = argparse.ArgumentParser(description="Select a file to upload to S3")61 parser.add_argument(62 "--file",63 "-f",64 #default='default',65 help="Specifies the file to be uploaded ",66 required=True67 )68 args = parser.parse_args()...

Full Screen

Full Screen

get_presigned_url.py

Source:get_presigned_url.py Github

copy

Full Screen

...14if __name__ == "__main__":15 import sys16 client_method = sys.argv[1]17 if client_method == 'list_buckets':18 url = cli.generate_presigned_url(19 ClientMethod='list_buckets',20 ExpiresIn=60000,21 )22 print url23 elif client_method == 'create_bucket':24 url = cli.generate_presigned_url(25 ClientMethod='create_bucket',26 Params={27 'Bucket': sys.argv[2],28 },29 ExpiresIn=60000,30 )31 print url32 elif client_method == 'put_object':33 url = cli.generate_presigned_url(34 ClientMethod='put_object',35 Params={36 'Bucket': sys.argv[2],37 'Key': sys.argv[3],38 },39 ExpiresIn=60000,40 )41 print url42 elif client_method == 'get_object':43 url = cli.generate_presigned_url(44 ClientMethod='get_object',45 Params={46 'Bucket': sys.argv[2],47 'Key': sys.argv[3],48 },49 ExpiresIn=60000,50 )51 print url52 elif client_method == 'list_objects':53 url = cli.generate_presigned_url(54 ClientMethod='list_objects',55 Params={56 'Bucket': sys.argv[2],57 },58 ExpiresIn=6000,59 )60 print url61 elif client_method == 'delete_object':62 url = cli.generate_presigned_url(63 ClientMethod='delete_object',64 Params={65 'Bucket': sys.argv[2],66 'Key': sys.argv[3],67 },68 ExpiresIn=60000,69 )70 print url71 elif client_method == 'delete_bucket':72 url = cli.generate_presigned_url(73 ClientMethod='delete_bucket',74 Params={75 'Bucket': sys.argv[2],76 },77 ExpiresIn=60000,78 )...

Full Screen

Full Screen

test_s3link.py

Source:test_s3link.py Github

copy

Full Screen

1import pytest2import botocore3import s3link4import test_constants5@pytest.fixture6def mock_s3(mocker):7 mocker.patch.object(s3link, 'S3')8 return s3link.S39@pytest.fixture10def mock_bucket(mocker):11 mocker.patch.object(s3link, 'BUCKET')12 return s3link.BUCKET13def test_get_presigned_url_none_key(mock_s3, mock_bucket):14 assert s3link.get_presigned_url(None) is None15 mock_bucket.Object.assert_not_called()16 mock_s3.generate_presigned_url.assert_not_called()17def test_get_presigned_url_key_not_found(mock_s3, mock_bucket):18 mock_bucket.Object.return_value.load.side_effect = botocore.exceptions.ClientError(19 {20 'Error': {21 'Code': '404'22 }23 }, None24 )25 assert s3link.get_presigned_url('foo') is None26 mock_bucket.Object.assert_called_with('foo')27 mock_s3.generate_presigned_url.assert_not_called()28def test_get_presigned_url_other_exception(mock_s3, mock_bucket):29 mock_bucket.Object.return_value.load.side_effect = botocore.exceptions.ClientError(30 {31 'Error': {32 'Code': 'boom!'33 }34 }, None35 )36 with pytest.raises(botocore.exceptions.ClientError):37 s3link.get_presigned_url('foo')38 mock_bucket.Object.assert_called_with('foo')39 mock_s3.generate_presigned_url.assert_not_called()40def test_get_presigned_url_key_exists(mock_s3, mock_bucket):41 mock_s3.generate_presigned_url.return_value = 'presigned-url'42 assert s3link.get_presigned_url('foo') == 'presigned-url'43 mock_bucket.Object.assert_called_with('foo')44 mock_bucket.Object.return_value.load.assert_called_with()45 mock_s3.generate_presigned_url.assert_called_with(46 ClientMethod='get_object',47 ExpiresIn=600,48 Params={49 'Bucket': test_constants.BUCKET_NAME,50 'Key': 'foo'51 }...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful