@@ -29,39 +29,73 @@ if [ ! -f "./functions.sh" ]; then
2929fi
3030source ./functions.sh
3131
32- log_message " Getting bucket names from SSM parameters"
32+ log_message " Getting bucket names from SSM parameters (using prod profile)"
33+ # Get S3 bucket base name using prod profile since SSM parameters are in prod account
34+ export AWS_PROFILE=prod
3335s3_bucket_zip_files
3436STAGING_BUCKET=" $S3 -staging"
3537PROD_BUCKET=" $S3 -$ENVIRONMENT "
3638
3739log_message " STAGING_BUCKET: $STAGING_BUCKET "
3840log_message " PROD_BUCKET: $PROD_BUCKET "
3941
40- log_message " Checking if version $VERSION exists in staging bucket"
42+ log_message " Checking if version $VERSION exists in staging bucket (using nonprod profile)"
43+
44+ # Switch to nonprod profile for staging bucket access
45+ export AWS_PROFILE=nonprod
4146aws s3 ls s3://$STAGING_BUCKET / | grep -v ' /$' | grep " v${VERSION} "
4247if [ $? -ne 0 ]; then
4348 log_message " ERROR: Version $VERSION not found in staging bucket $STAGING_BUCKET "
4449 exit 1
4550fi
4651log_message " Version $VERSION found in staging bucket"
4752
48- log_message " Copying versioned artifacts from staging to prod"
49- artifacts_copied=0
50- aws s3 ls s3://$STAGING_BUCKET / | grep -v ' /$' | grep " v${VERSION} " | awk ' {print $4}' | while read FILENAME; do
51- log_message " Copying $FILENAME from staging to prod"
52- aws s3 cp s3://$STAGING_BUCKET /$FILENAME s3://$PROD_BUCKET /$FILENAME
53- artifacts_copied=$(( artifacts_copied + 1 ))
53+ # Create temporary directory for artifacts
54+ TEMP_DIR=" /tmp/artifacts_v${VERSION} "
55+ mkdir -p " $TEMP_DIR "
56+ log_message " Created temporary directory: $TEMP_DIR "
57+
58+ log_message " Downloading versioned artifacts from staging to local runner (using nonprod profile)"
59+ artifacts_downloaded=0
60+
61+ # Use nonprod profile for staging bucket access
62+ export AWS_PROFILE=nonprod
63+ while read FILENAME; do
64+ log_message " Downloading $FILENAME from staging to local runner"
65+ aws s3 cp s3://$STAGING_BUCKET /$FILENAME " $TEMP_DIR /$FILENAME "
66+ artifacts_downloaded=$(( artifacts_downloaded + 1 ))
67+ done < <( aws s3 ls s3://$STAGING_BUCKET / | grep -v ' /$' | grep " v${VERSION} " | awk ' {print $4}' )
68+
69+ log_message " Downloaded $artifacts_downloaded artifacts to local runner"
70+
71+ log_message " Uploading artifacts from local runner to prod bucket (using prod profile)"
72+ artifacts_uploaded=0
73+ # Switched to prod profile for prod bucket access
74+ export AWS_PROFILE=prod
75+ for FILENAME in " $TEMP_DIR " /* ; do
76+ if [ -f " $FILENAME " ]; then
77+ BASENAME=$( basename " $FILENAME " )
78+ log_message " Uploading $BASENAME from runner to prod bucket"
79+ aws s3 cp " $FILENAME " s3://$PROD_BUCKET /$BASENAME
80+ artifacts_uploaded=$(( artifacts_uploaded + 1 ))
81+ fi
5482done
5583
56- log_message " $artifacts_copied artifacts copied successfully"
84+ log_message " $artifacts_uploaded artifacts uploaded successfully to prod"
85+
86+ # Clean up temporary directory
87+ rm -rf " $TEMP_DIR "
88+ log_message " Cleaned up temporary directory"
5789
5890export SEMANTIC_VERSION=" $VERSION "
5991
6092
6193log_message " Running update-lambda-functions.sh with version $SEMANTIC_VERSION "
6294./update-lambda-functions.sh " $SEMANTIC_VERSION "
6395
64- log_message " Verifying Lambda deployments in $ENVIRONMENT environment"
96+ log_message " Verifying Lambda deployments in $ENVIRONMENT environment (using prod profile)"
97+
98+ export AWS_PROFILE=prod
6599
66100CORE_LAMBDA=$( aws ssm get-parameter \
67101 --name /lambda/kccorename \
0 commit comments