AWS_ACCOUNT_ID=727401853962
#ROLE_NAME=jamtrack-processor-test
ROLE_NAME=JamKazamJamTracksBatchRole
REPORT_BUCKET=jamkazam-tency-202410-test
SOURCE_BUCKET=jamkazam-tency-uploads-test
#LAMBDA_FUNCTION_ARN=arn:aws:lambda:us-east-1:727401853962:function:jamtrack-processing-ZipExtractorFunction-thM3NERnsIBg
#https://us-east-1.console.aws.amazon.com/s3/object/jamkazam-tency-uploads-test?region=us-east-1&bucketType=general&prefix=manifest.csv
MANIFEST_ETAG=da094abf7ed6cbd4ad41273c328d72b8
TOKEN=$(uuidgen)

set -eu -o pipefail

JOB_ID=$(aws s3control create-job \
    --account-id $AWS_ACCOUNT_ID \
    --operation '{"LambdaInvoke": {"FunctionArn": "'$LAMBDA_FUNCTION_ARN'"}}' \
    --manifest '{"Spec": {"Format": "S3BatchOperations_CSV_20180820", "Fields": ["Bucket", "Key"]}, "Location": {"ObjectArn": "arn:aws:s3:::'$SOURCE_BUCKET'/manifest-full.csv", "ETag": "'$MANIFEST_ETAG'"}}' \
    --report '{"Bucket": "arn:aws:s3:::'$REPORT_BUCKET'", "Prefix": "reports/", "Format": "Report_CSV_20180820", "Enabled": true, "ReportScope": "AllTasks"}' \
    --priority 42 \
    --role-arn arn:aws:iam::$AWS_ACCOUNT_ID:role/$ROLE_NAME \
    --description "Batch job to process zip files in S3 bucket" \
    --client-request-token "'$TOKEN'" \
    --region us-east-1 \
    --no-confirmation-required \
    --query "JobId" --output text)

echo $JOB_ID

echo "https://us-east-1.console.aws.amazon.com/s3/jobs/$JOB_ID?region=us-east-1"

echo "Activated S3 Batch Operations Job with ID: $JOB_ID"

