Flask extension that ties boto3 connectors to the application context. To be used with Python 3.6+.
-
Via the cheeseshop
$ pip install flask-boto3
-
Locally with Pipenv
$ git clone git@github.com:Ketouem/flask-boto3.git $ cd flask-boto3 flask-boto3 $ pipenv install -e .
The main class flask_boto3.Boto3
takes a Flask application as its contructor's parameter:
from flask import Flask
from flask_boto3 import Boto3
app = Flask(__name__)
app.config['BOTO3_SERVICES'] = ['s3']
boto_flask = Boto3(app)
Then boto3
's clients and resources will be available as properties within the application context:
>>> with app.app_context():
print(boto_flask.clients)
print(boto_flask.resources)
{'s3': <botocore.client.S3 object at 0x..>}
{'s3': s3.ServiceResource()}
flask-boto3 uses several keys from a Flask configuration objects to customize its behaviour:
BOTO3_ACCESS_KEY
&BOTO3_SECRET_KEY
: holds the AWS credentials, ifNone
the extension will rely onboto3
's default credentials lookup.BOTO3_REGION
: holds the region that will be used for all connectors.BOTO3_PROFILE
: holds the AWS profile.BOTO3_SERVICES
: holds, as a list, the name of the AWS resources you want to use (e.g.['sqs', 's3']
).BOTO3_OPTIONAL_PARAMS
: useful when you need to pass additional parameters to the connectors (e.g. for testing purposes), the format is adict
where the top-level keys are the name of the services you're using and for each the value is adict
containing to keysargs
(contains the parameters astuple
) andkwargs
(contains the parameters as adict
when they should be passed as keyword arguments).