Skip to content

Instantly share code, notes, and snippets.

@ilyesAj
Created August 22, 2022 14:31
Show Gist options
  • Save ilyesAj/ed1cdb588597252f48e4fceeb2085a0f to your computer and use it in GitHub Desktop.
Save ilyesAj/ed1cdb588597252f48e4fceeb2085a0f to your computer and use it in GitHub Desktop.
aws cp job kubernetes
apiVersion: v1
kind: Namespace
metadata:
name: s3-copy
---
apiVersion: batch/v1
kind: Job
metadata:
name: s3-bucket-a-sync
namespace: s3-copy
spec:
backoffLimit: 0
template:
metadata:
name: s3-sync
spec:
containers:
- image: amazon/aws-cli
name: s3-sync
command: ["/bin/sh"]
args:
- -c
- "/scripts/run.sh"
env:
- name: AWS_SECRET_ACCESS_KEY
valueFrom:
secretKeyRef:
name: aws-s3-sync-credentials
key: AWS_SECRET_ACCESS_KEY
- name: AWS_ACCESS_KEY_ID
valueFrom:
secretKeyRef:
name: aws-s3-sync-credentials
key: AWS_ACCESS_KEY_ID
- name: SOURCE_BUCKET
value: bucket-a
- name: DESTINATION_BUCKET
value: bucket-b
- name: SOURCE_REGION
value: eu-west-1
- name: DESTINATION_REGION
value: eu-west-3
volumeMounts:
- name: script
mountPath: /scripts
resources:
requests:
cpu: 300m
memory: 200Mi
limits:
cpu: 500m
memory: 400Mi
restartPolicy: Never
volumes:
- name: script
configMap:
name: s3-sync
defaultMode: 0777
---
apiVersion: v1
kind: ConfigMap
metadata:
name: s3-sync
namespace: s3-copy
labels:
app: s3-sync
data:
run.sh: |
#!/bin/sh
echo "[DEBUG] BEGIN COPY"
echo "[DEBUG] aws s3 sync s3://$SOURCE_BUCKET s3://$DESTINATION_BUCKET --source-region $SOURCE_REGION --region $DESTINATION_REGION --no-progress "
aws s3 sync s3://$SOURCE_BUCKET s3://$DESTINATION_BUCKET --source-region $SOURCE_REGION --region $DESTINATION_REGION --no-progress
echo "[DEBUG] COPY FINISH"
---
apiVersion: v1
kind: Secret
metadata:
name: aws-s3-sync-credentials
namespace: s3-copy
type: Opaque
stringData:
AWS_ACCESS_KEY_ID: XX
AWS_SECRET_ACCESS_KEY: XX
@ilyesAj
Copy link
Author

ilyesAj commented Aug 24, 2022

full implementation of this code here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment