22
33source ./scripts/cloud-utils.sh
44
5+ # Function to convert S3 ARN to S3 URI
6+ function convertArnToUri {
7+ local arn=" $1 "
8+
9+ # Remove "arn:aws:s3:::" from the beginning of the ARN
10+ local stripped_arn=" ${arn# arn: aws: s3::: } "
11+
12+ # Extract the bucket name and object key
13+ local bucket_name=" ${stripped_arn%%/* } "
14+ local object_key=" ${stripped_arn#*/ } "
15+
16+ # Create the S3 URI
17+ local s3_uri=" s3://$bucket_name /$object_key "
18+
19+ echo " $s3_uri "
20+ }
21+
522function downloadS3Artifact {
623 # Get temporary access for the account
724 E2E_ROLE_NAME=CodebuildDeveloper
825 E2E_PROFILE_NAME=AmplifyAPIE2EProd
926 authenticate $E2E_ACCOUNT_PROD $E2E_ROLE_NAME " $E2E_PROFILE_NAME "
1027
11- local s3_object_uri=$1
12- local destination_dir=$2
28+ echo " Fetching artifact location from build"
29+ s3_arn=$( aws codebuild batch-get-builds --profile=" $E2E_PROFILE_NAME " --ids " $1 " --region us-east-1 --query ' builds[0].artifacts.location' )
30+ # Have to remove double quote for arn
31+ s3_object_uri=$( convertArnToUri ${s3_arn// \" / } )
1332
1433 echo " Downloading objects from S3 bucket..."
15- aws s3 cp " $s3_object_uri " " $destination_dir " --recursive --profile=" $E2E_PROFILE_NAME "
16- echo " Download complete. Files are saved in: $destination_dir "
34+ aws s3 cp $s3_object_uri $2 --recursive --profile=" $E2E_PROFILE_NAME "
35+ echo " Download complete. Files are saved in: $2 "
1736}
1837
1938function playTestArtifact {
2039 # Check if an S3 object URI is provided
2140 if [ $# -eq 0 ]; then
22- echo " Provide the S3 URI of the artifact : $0 <s3_object_uri >"
41+ echo " Provide the code build id : $0 <code_build_id >"
2342 exit 1
2443 fi
2544
@@ -29,7 +48,7 @@ function playTestArtifact {
2948 trap " cleanup $temp_dir " SIGINT SIGTERM # Register cleanup function to handle Ctrl+C
3049
3150 echo " Starting test artifact playback..."
32- downloadS3Artifact " $s3_object_uri " " $temp_dir "
51+ downloadS3Artifact " $code_build_id " " $temp_dir "
3352
3453
3554 local subfolders=(" $temp_dir " /* /)
0 commit comments