I made a simple CI/CD with Github Action. This time I uploaded the yaml file of cloudformation, first pushed it to one of my S3 Bucket, and then used this yaml file to generate the corresponding service.
https://github.com/vetpartner/cf
The workflow file is as follows, first checkout, then check the syntax of cloudformation, then use the secret value to perform aws login verification, then copy the file, and then configure cloudformation. There are various actions written by other people on Github action to perform various tall operations. Here I use aws cli directly.
# This is a basic workflow to help you get started with Actions
name: aws
# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches:
- master
jobs:
deploy:
name: Upload to Amazon
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Check cloudformation yaml file
uses: scottbrenner/cfn-lint-action@master
with:
args: "*.yaml"
- name: Configure AWS credentials from Production account
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-southeast-2
- name: Copy files to the production website with the AWS CLI
run: |
aws s3 sync . s3://yuanlitest
- name: Deploy to AWS CloudFormation
run: aws cloudformation create-stack --stack-name myteststack2 --template-body file://vpc.yaml --parameter ParameterKey=S3BucketName,ParameterValue=githubtestcicds3bucket1 ParameterKey=UserName,ParameterValue=githubuser1 ParameterKey=PolicyName,ParameterValue=githubtests3bucket1 --capabilities CAPABILITY_NAMED_IAM
You can see that my cf was successfully executed