2
2
3
3
source ./scripts/cloud-utils.sh
4
4
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
+
5
22
function downloadS3Artifact {
6
23
# Get temporary access for the account
7
24
E2E_ROLE_NAME=CodebuildDeveloper
8
25
E2E_PROFILE_NAME=AmplifyAPIE2EProd
9
26
authenticate $E2E_ACCOUNT_PROD $E2E_ROLE_NAME " $E2E_PROFILE_NAME "
10
27
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// \" / } )
13
32
14
33
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 "
17
36
}
18
37
19
38
function playTestArtifact {
20
39
# Check if an S3 object URI is provided
21
40
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 >"
23
42
exit 1
24
43
fi
25
44
@@ -29,7 +48,7 @@ function playTestArtifact {
29
48
trap " cleanup $temp_dir " SIGINT SIGTERM # Register cleanup function to handle Ctrl+C
30
49
31
50
echo " Starting test artifact playback..."
32
- downloadS3Artifact " $s3_object_uri " " $temp_dir "
51
+ downloadS3Artifact " $code_build_id " " $temp_dir "
33
52
34
53
35
54
local subfolders=(" $temp_dir " /* /)
0 commit comments