diff --git a/.github/scripts/run.sh b/.github/scripts/run.sh index 41588fe..6ff8d5c 100644 --- a/.github/scripts/run.sh +++ b/.github/scripts/run.sh @@ -5,15 +5,15 @@ set -o pipefail # Exit if any command in a pipeline fails # Function to fetch a parameter and exit if it's empty fetch_parameter() { - local value - # Add the --region flag to the aws command - value=$(aws ssm get-parameter --name "$1" --with-decryption --query 'Parameter.Value' --output text --region "${AWS_REGION}" | tr -d '\r\n') - if [ -z "$value" ]; then - echo "Error: SSM Parameter $1 is empty or could not be fetched." >&2 - exit 1 - fi - echo "$value" - } + local value + local region="${AWS_REGION:-eu-north-1}" + value=$(aws ssm get-parameter --name "$1" --with-decryption --query 'Parameter.Value' --output text --region "$region" | tr -d '\r\n') + if [ -z "$value" ]; then + echo "Error: SSM Parameter $1 is empty or could not be fetched." >&2 + exit 1 + fi + echo "$value" +} # Fetch secrets from AWS SSM Parameter Store APP_BASE_URL=$(fetch_parameter "/unraveldocs/APP_BASE_URL") diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 7fc6f47..5c18987 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -49,9 +49,10 @@ jobs: host: ${{ secrets.EC2_HOST }} username: ${{ secrets.EC2_USERNAME }} key: ${{ secrets.EC2_SSH_KEY }} - env: + envs: AWS_REGION: ${{ env.AWS_REGION }} script: | + export AWS_REGION=${{ env.AWS_REGION }} # The EC2 instance role will be used for AWS commands # Log in to ECR using the instance role aws ecr get-login-password --region ${{ env.AWS_REGION }} | docker login --username AWS --password-stdin ${{ env.ECR_REGISTRY }}