On your local machine, create your Python script and package the script and a boto3 library as a ZIP folder.
Procedure
- On your local machine, create a vro-python-aws folder, and install the boto3 Python SDK on it.
mkdir vro-python-aws
cd vro-python-aws
mkdir lib
pip install boto3 -t lib/
- Open an editor, and create the main Python script. For this use case, you are using Visual Studio Code.
import boto3
def handler(context, inputs):
ec2 = boto3.resource('ec2')
filters = [{
'Name': 'instance-state-name',
'Values': ['running']
}]
instances = ec2.instances.filter(Filters=filters)
for instance in instances:
print('Instance: ' + instance.id)
This Python script lists all running EC2 instances in a given region.
- Save the created script as a main.py file in the vro-python-aws folder.
- Log in to a command-line interface.
- Navigate to the vro-python-aws folder.
- Create a ZIP package that contains the Python script.
zip -r --exclude=*.zip -X vro-python-aws.zip .
Note: You can also create the ZIP package by using a ZIP utility tool, such as 7-Zip.
Results
You have created the base Python script, and prepared it for import into your vRealize Orchestrator deployment.