Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Deploy Template files | |
on: | |
pull_request: | |
branches: | |
- main | |
paths: | |
- '*.yaml' | |
jobs: | |
build-and-deploy: | |
runs-on: ubuntu-latest | |
permissions: | |
id-token: write | |
contents: write | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Setup Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: '1.22' | |
- name: Install AWS SAM CLI | |
run: | | |
pip install aws-sam-cli | |
# modify lambda CodeUri to production as s3 bucket destination | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.x' | |
- name: Install PyYAML | |
run: | | |
python -m pip install --upgrade pip | |
pip install pyyaml | |
- name: Run Python Script to Update lambda-template.yaml | |
run: python scripts/update_yaml.py | |
- name: Verify the changes | |
run: cat lambda-template.yaml | |
- name: Configure AWS Credentials | |
uses: aws-actions/configure-aws-credentials@v3 | |
with: | |
role-to-assume: ${{ secrets.AWS_S3_PUBLISH_ROLE_TEMP }} | |
aws-region: us-east-2 | |
- name: Build and Package SAM Application and Upload to S3 | |
env: | |
bucket_name: anusha-test-ansuha | |
run: | | |
TEMPLATES=( | |
"logging-lambda-metric-polling.yaml" | |
"logging-lambda-metric-stream.yaml" | |
"logging-firehose-metric-polling.yaml" | |
"logging-firehose-metric-stream.yaml" | |
"logging-lambda-firehose-metric-polling.yaml" | |
"logging-lambda-firehose-metric-stream.yaml" | |
"lambda-template.yaml" | |
"logging-lambda-firehose-template.yaml" | |
) | |
for TEMPLATE_FILE in "${TEMPLATES[@]}"; do | |
BASE_NAME=$(basename "$TEMPLATE_FILE" .yaml) | |
BUILD_DIR=".aws-sam/build/$BASE_NAME" | |
sam build --template-file "$TEMPLATE_FILE" --build-dir "$BUILD_DIR" | |
sam package --s3-bucket "$bucket_name" --template-file "$BUILD_DIR/template.yaml" --output-template-file "$BUILD_DIR/$TEMPLATE_FILE" | |
if [[ $? -ne 0 ]]; then | |
echo "Error: Failed to package template $TEMPLATE_FILE" | |
fi | |
max_retries=3 | |
retry_delay=5 | |
attempt=0 | |
success=false | |
while [[ $attempt -lt $max_retries ]]; do | |
echo "Attempt $(($attempt + 1)) to upload $TEMPLATE_FILE to S3 bucket $bucket_name" | |
aws s3 cp "$BUILD_DIR/$TEMPLATE_FILE" "s3://$bucket_name/$TEMPLATE_FILE" | |
if [[ $? -eq 0 ]]; then | |
success=true | |
echo "Deployment of $TEMPLATE_FILE completed" | |
break | |
else | |
echo "Error: Failed to copy $TEMPLATE_FILE to S3 bucket $bucket_name. Retrying in $retry_delay seconds..." | |
sleep $retry_delay | |
fi | |
attempt=$(($attempt + 1)) | |
done | |
if ! $success; then | |
echo "Error: Failed to copy $TEMPLATE_FILE to S3 bucket $bucket_name after $max_retries attempts." | |
fi | |
done |