Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 4231399

Browse files
First demo
Add simple example of using Boto3 library on Outscale OOS service. This will show examples of: - Creating / Deleting a bucket - Creating / Deleting an object Signed-off-by: Jérôme Jutteau <[email protected]>
1 parent 409fe28 commit 4231399

File tree

5 files changed

+173
-0
lines changed

5 files changed

+173
-0
lines changed

.github/workflows/cred-scan.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Credential Scanner
2+
3+
on:
4+
pull_request:
5+
branches: [ main ]
6+
7+
jobs:
8+
cred-scan:
9+
runs-on: ubuntu-20.04
10+
steps:
11+
- uses: actions/checkout@v2
12+
- name: Scan credentials
13+
uses: outscale-dev/cred-scan@main
14+
with:
15+
scan_path: "./"

LICENSE

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Copyright (c) 2022 Outscale SAS. All rights reserved.
2+
3+
Redistribution and use in source and binary forms, with or without modification,
4+
are permitted provided that the following conditions are met:
5+
6+
1. Redistributions of source code must retain the above copyright notice,
7+
this list of conditions and the following disclaimer.
8+
9+
2. Redistributions in binary form must reproduce the above copyright notice,
10+
this list of conditions and the following disclaimer in the documentation
11+
and/or other materials provided with the distribution.
12+
13+
3. Neither the name of the copyright holder nor the names of its contributors
14+
may be used to endorse or promote products derived from this software without
15+
specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
26+
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Using Outscale Object Storage with Python
2+
3+
This small example project shows how to use [OOS](https://docs.outscale.com/en/userguide/OUTSCALE-Object-Storage-(OOS).html) using standard [boto3](https://boto3.amazonaws.com/v1/documentation/api/latest/index.html) library.
4+
5+
Running this example will:
6+
- Create a Bucket with a random name
7+
- Put a string inside an object inside the bucket
8+
- Read back that object
9+
- Delete the object
10+
- Delete the bucket
11+
12+
# Pre-requisites
13+
14+
You will need:
15+
- python3 and preferably virtualenv installed
16+
- An [Access Key and Secret Key](https://docs.outscale.com/en/userguide/About-Access-Keys.html)
17+
18+
# Running the example
19+
20+
1. (optional) Setup your virtual env:
21+
```bash
22+
virtualenv -p python3 .venv
23+
source .venv/bin/activate
24+
```
25+
26+
2. Install dependencies
27+
28+
```bash
29+
pip install -r requirements.txt
30+
```
31+
32+
3. Setup your credentials and region:
33+
34+
```bash
35+
export OSC_REGION="eu-west-2"
36+
export OSC_ACCESS_KEY="MyAccessKey"
37+
export OSC_SECRET_KEY="MySecretKey"
38+
```
39+
40+
4. Run the example:
41+
42+
```bash
43+
> python src/main.py
44+
```
45+
46+
You should have a similar output:
47+
```bash
48+
> python src/main.py
49+
creating private bucket named bucket-test-voxa...
50+
bucket bucket-test-voxa created
51+
writing 'Hello World' to public my-data object...
52+
writed to bucket-test-voxa object
53+
reading my-data object...
54+
read object ok: b'Hello World'
55+
deleting my-data object...
56+
deleted my-data object
57+
deleting bucket named bucket-test-voxa...
58+
bucket bucket-test-voxa delete
59+
```
60+
61+
Check [main.py](src/main.py) to see how it is done.
62+
63+
# Contribution guidelines
64+
65+
Feel free to open an issue for discussion or bug report.
66+
67+
# License
68+
69+
> Copyright Outscale SAS
70+
>
71+
> BSD-3-Clause

requirements.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
boto3==1.24.0
2+
botocore==1.27.0
3+
jmespath==1.0.0
4+
python-dateutil==2.8.2
5+
s3transfer==0.6.0
6+
six==1.16.0
7+
urllib3==1.26.9

src/main.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import os
2+
import string
3+
import random
4+
import sys
5+
import boto3
6+
from botocore.client import ClientError
7+
8+
# This is a small example of using Outscale Object Storage using Boto3 library
9+
#
10+
# Check boto3 documentation regarding s3 actions for more details
11+
# https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#S3.Client
12+
def demo():
13+
try:
14+
s3 = s3_client()
15+
bucket_name = "bucket-test-" + random_name(4)
16+
print("creating private bucket named %s..." % bucket_name)
17+
s3.create_bucket(ACL='private', Bucket=bucket_name)
18+
print("bucket %s created" % bucket_name)
19+
20+
object_name = "my-data"
21+
print("writing 'Hello World' to public %s object..." % object_name)
22+
s3.put_object(ACL='public-read', Body=b'Hello World', Bucket=bucket_name, Key=object_name)
23+
print("writed to %s object" % bucket_name)
24+
25+
print("reading %s object..." % object_name)
26+
obj = s3.get_object(Bucket=bucket_name, Key=object_name)
27+
print("read object ok: %s" % obj['Body'].read())
28+
29+
print("deleting %s object..." % object_name)
30+
s3.delete_object(Bucket=bucket_name, Key=object_name)
31+
print("deleted %s object" % object_name)
32+
33+
print("deleting bucket named %s..." % bucket_name)
34+
bucket = s3.delete_bucket(Bucket=bucket_name)
35+
print("bucket %s deleted" % bucket_name)
36+
except ClientError as error:
37+
print(error, file=sys.stderr)
38+
sys.exit(1)
39+
40+
def s3_client():
41+
access_key = os.environ['OSC_ACCESS_KEY']
42+
secret_key = os.environ['OSC_SECRET_KEY']
43+
region = os.environ['OSC_REGION']
44+
endpoint = 'https://oos.%s.outscale.com' % region
45+
s3_client = boto3.client(service_name='s3', region_name=region, use_ssl=True, endpoint_url=endpoint, aws_access_key_id=access_key, aws_secret_access_key=secret_key)
46+
return s3_client
47+
48+
def random_name(size):
49+
letters = string.ascii_lowercase
50+
name = ''.join(random.choice(letters) for i in range(size))
51+
return name
52+
53+
if __name__ == "__main__":
54+
demo()

0 commit comments

Comments
 (0)