.. | ||
samples | ||
python-boto3-aws.yaml | ||
README.md |
Python Boto3 Task
This Tekton Task defines a reusable Task named python-boto3
for running Python scripts that use the boto3 library to interact with AWS services.
Parameters
The Task accepts the following parameters:
aws-region
(optional, default:us-east-1
): The AWS region to use for the boto3 client.
Volumes
The Task expects a ConfigMap named python-script-configmap
to be mounted as a volume named python-script
. This ConfigMap should contain the Python script to be executed, with the key script.py
.
Steps
The Task consists of a single step that runs the Python script using the python:3.9
image. The step performs the following actions:
- Installs the
boto3
library usingpip
. - Sets the AWS credentials as environment variables (
AWS_ACCESS_KEY_ID
andAWS_SECRET_ACCESS_KEY
) from a Kubernetes Secret namedaws-credentials
. - Sets the AWS region as an environment variable (
AWS_DEFAULT_REGION
) using the value provided in theaws-region
parameter. - Mounts the
python-script
volume containing the Python script at/workspace/python-script
. - Executes the Python script located at
/workspace/python-script/script.py
.
Usage
To use this Task, you'll need to create the following resources:
- A Kubernetes Secret named
aws-credentials
with your AWS Access Key ID and Secret Access Key. - A ConfigMap named
python-script-configmap
with your Python script (script.py
).
Python script named script.py with the following content:
#####################################################
script.py - begin
##################################################### import boto3
Your Python script that uses boto3 goes here
For example:
s3 = boto3.client('s3') response = s3.list_buckets()
print(response)
###################################################
script.py - end
################################################### To create the ConfigMap, you can use the kubectl create configmap command and specify the --from-file flag to include the Python script file:
command to create configmap
kubectl create configmap python-script-configmap --from-file=script.py This command will create a ConfigMap named python-script-configmap with the contents of the script.py file. Alternatively you can also use config-map.yaml given in sample
Then, you can create a Tekton TaskRun that references this Task and provide the necessary parameters (if any).