Make boto3 calls that look real but have no effect
pip install placeboplacebo
Placebo allows you to mock boto3 calls that look just like normal calls but actually have no effect at all. It does this by allowing you to record a set of calls and save them to a data file and then replay those calls later (e.g. in a unit test) without ever hitting the AWS endpoints.
Installation
$ pip install placebo
Quickstart
Placebo uses the event mechanism in botocore to do most of its work. To start with, you need a boto3 Session object.
import boto3
import placebo
session = boto3.Session()
Once you have a Session object, you can tell placebo about the Session like this:
pill = placebo.attach(session, data_path='/path/to/response/directory')
The data_path is a path to a directory where you want responses to be stored
or that contains previously recorded responses you want to playback.
The attach function returns an instance of a Pill object. This object
will be used to control all recording and playback of requests for all clients
created by this session object.
The first thing you will probably want to do is record some requests. To do this, simply:
pill.record()
By default, the record method will cause all responses from all services to
be recorded to the data_path. If you are only interested in responses from
one certain services, you can limit the recording by passing in a list of
service names.
pill.record(services='ec2,iam')
This would limit to recording to responses from the ec2 service and the
iam service. If you want to restrict recording to only certain operations
in a single service, you can do this:
pill.record(services='ec2', operations='DescribeInstances,DescribeKeyPairs')
From this point on, any clients that match the recording specification and are created from the session will be placebo-aware. To record responses, just create the client and use it as you normally would.
aws_lambda = session.client('lambda')
aws_lambda.list_functions()
# ... more lambda calls ...
Each response will be saved as an individual JSON data file in the path you specified when you attached the session. Multiple responses from the same service and operation are stored as separate files and will be replayed in the same order on playback.