-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
73 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
name: Deploy AWS Lambda | ||
|
||
on: | ||
- push | ||
|
||
jobs: | ||
sam-deploy: | ||
runs-on: ubuntu-latest | ||
|
||
outputs: | ||
env-name: ${{ steps.env-name.outputs.environment }} | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up JDK 11 | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: '11' | ||
distribution: 'adopt' | ||
cache: maven | ||
- name: Configure AWS credentials | ||
id: creds | ||
uses: aws-actions/configure-aws-credentials@v4 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws-region: ${{ secrets.AWS_REGION }} | ||
- name: SAM Validate | ||
run: sam validate --lint | ||
working-directory: deploy/aws | ||
- name: Configure variables | ||
shell: bash | ||
id: vars | ||
env: | ||
REPO: ${{ github.repository }} | ||
HASH: ${{ github.sha }} | ||
REF: ${{ github.ref }} | ||
run: | | ||
# Set variables | ||
BRANCH=${REF#refs/heads/} | ||
BRANCH=main | ||
REPOSITORY=`echo $REPO | cut -d'/' -f2` | ||
ENVIRONMENT=$REPOSITORY-$BRANCH-${{ secrets.AWS_REGION }} | ||
# In this step we are setting variables and persistenting them | ||
# into the environment so that they can be utilized in other steps | ||
echo "branch=$BRANCH" >> $GITHUB_OUTPUT | ||
echo "repository=$REPOSITORY" >> $GITHUB_OUTPUT | ||
echo "environment=$ENVIRONMENT" >> $GITHUB_OUTPUT | ||
# Output variables to ensure their values are set correctly when ran | ||
echo "The region is ${{ secrets.AWS_REGION }}" | ||
echo "The repository is $REPOSITORY" | ||
echo "The environment is $ENVIRONMENT" | ||
echo "The branch is $BRANCH" | ||
- name: Clear SAM outputs | ||
run: yq eval 'del(.Outputs)' -i template.yaml | ||
working-directory: deploy/aws | ||
- name: SAM Build and Run Unit Tests | ||
run: sam build --parallel | ||
working-directory: deploy/aws | ||
- name: SAM Deploy | ||
run: | | ||
# Create S3 Bucket to store code | ||
aws s3api head-bucket --bucket "${{ steps.vars.outputs.environment }}" 2>/dev/null \ | ||
|| aws s3 mb s3://${{ steps.vars.outputs.environment }} | ||
# Run SAM Deploy | ||
sam deploy --template-file .aws-sam/build/template.yaml \ | ||
--stack-name ${{ steps.vars.outputs.environment }} \ | ||
--s3-bucket ${{ steps.vars.outputs.environment }} \ | ||
--parameter-overrides \ | ||
'ParameterKey=Version,ParameterValue=${{ steps.vars.outputs.version }}' \ | ||
--capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM \ | ||
--no-fail-on-empty-changeset | ||
working-directory: deploy/aws |