Skip to main content

How to connect a bucket from an application

This guide explains how to use the credentials of a Hikube S3 user from an application: environment variables, the Python SDK (boto3), and injection into a pod of your Kubernetes cluster.

Prerequisites​

  • A bucket and an S3 user created from the Hikube console, with their keys (see Manage users and access keys)
  • Depending on the case: AWS CLI, Python with boto3 (pip install boto3), or a Kubernetes cluster and its kubeconfig

Steps​

1. Gather the connection information​

InformationWhere to find it
EndpointBucket page, Access & Configuration card, Endpoint field
S3 bucket nameSame card, Bucket name field
Access Key ID / Secret Access KeyDisplayed when the user is created
note

The S3 bucket name is generated by the platform (bucket-…) and differs from the name chosen in the console. Always use the S3 name in your application: with the console name, requests are refused (AccessDenied).

2. Expose the credentials as environment variables​

Most S3 SDKs and tools read the standard variables:

export AWS_ACCESS_KEY_ID="<access-key>"
export AWS_SECRET_ACCESS_KEY="<secret-key>"
export S3_ENDPOINT="https://<endpoint>"
export BUCKET_NAME="<bucket>"

Test with the AWS CLI:

# Upload, list and download a file
aws s3 cp fichier.txt "s3://$BUCKET_NAME/" --endpoint-url "$S3_ENDPOINT"
aws s3 ls "s3://$BUCKET_NAME/" --endpoint-url "$S3_ENDPOINT"
aws s3 cp "s3://$BUCKET_NAME/fichier.txt" ./fichier-download.txt --endpoint-url "$S3_ENDPOINT"

3. Use the bucket with Python (boto3)​

s3_example.py
import os

import boto3

s3 = boto3.client(
"s3",
endpoint_url=os.environ["S3_ENDPOINT"],
aws_access_key_id=os.environ["AWS_ACCESS_KEY_ID"],
aws_secret_access_key=os.environ["AWS_SECRET_ACCESS_KEY"],
)
bucket_name = os.environ["BUCKET_NAME"]

# Upload a file
s3.upload_file("local-file.txt", bucket_name, "remote-file.txt")
print("Upload complete")

# Download a file
s3.download_file(bucket_name, "remote-file.txt", "downloaded.txt")
print("Download complete")

# List objects
response = s3.list_objects_v2(Bucket=bucket_name)
for obj in response.get("Contents", []):
print(f" {obj['Key']} ({obj['Size']} bytes)")
python s3_example.py

4. Use the bucket from a Kubernetes cluster​

If your application runs in a Hikube Kubernetes cluster, store the credentials in a Secret of your cluster (with the kubeconfig downloaded from the cluster page):

kubectl create secret generic s3-credentials \
--from-literal=AWS_ACCESS_KEY_ID="<access-key>" \
--from-literal=AWS_SECRET_ACCESS_KEY="<secret-key>" \
--from-literal=S3_ENDPOINT="https://<endpoint>" \
--from-literal=BUCKET_NAME="<bucket>"

Inject them into your application:

app-with-bucket.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 1
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: app
image: my-app:latest
envFrom:
- secretRef:
name: s3-credentials
kubectl apply -f app-with-bucket.yaml
tip

Do not commit the keys in your manifests. Create the Secret separately (or through your secrets management tool) and reference it only by its name.

Verification​

  1. Upload a test file and check that it is present:
echo "test" > /tmp/test-hikube.txt
aws s3 cp /tmp/test-hikube.txt "s3://$BUCKET_NAME/test.txt" --endpoint-url "$S3_ENDPOINT"
aws s3 ls "s3://$BUCKET_NAME/" --endpoint-url "$S3_ENDPOINT"

Expected result:

2026-01-15 10:30:00 5 test.txt
  1. Delete the test file:
aws s3 rm "s3://$BUCKET_NAME/test.txt" --endpoint-url "$S3_ENDPOINT"

Further reading​