|
| 1 | +--- |
| 2 | +name: "Deploy CloudFormation Stack" |
| 3 | + |
| 4 | +on: |
| 5 | + workflow_call: |
| 6 | + inputs: |
| 7 | + s3-bucket: |
| 8 | + description: 'Add bucket name' |
| 9 | + required: true |
| 10 | + type: string |
| 11 | + bucket-prefix: |
| 12 | + description: 'bucket folder name' |
| 13 | + required: true |
| 14 | + type: string |
| 15 | + aws-region: |
| 16 | + description: 'AWS REGION' |
| 17 | + required: false |
| 18 | + default: 'us-east-1' |
| 19 | + type: string |
| 20 | + stack-name: |
| 21 | + description: 'Stack name defined' |
| 22 | + required: true |
| 23 | + type: string |
| 24 | + template-path: |
| 25 | + description: 'Cloudformation template path add here' |
| 26 | + required: true |
| 27 | + type: string |
| 28 | + organization-name: |
| 29 | + description: ' GitHub organization name' |
| 30 | + required: true |
| 31 | + type: string |
| 32 | + GitHub-repo-name: |
| 33 | + description: ' GitHub repo name' |
| 34 | + required: true |
| 35 | + type: string |
| 36 | + GitHub-branch: |
| 37 | + description: 'GitHub branch name' |
| 38 | + required: true |
| 39 | + default: 'main' |
| 40 | + type: string |
| 41 | + code-folder: |
| 42 | + description: 'Code folder where your lambda code stored ex-src(format-.ts/.py)' |
| 43 | + required: false |
| 44 | + default: 'src' |
| 45 | + type: string |
| 46 | + zip-file-name: |
| 47 | + description: 'Name of zip file which converted into zip & adding into S3 bucket' |
| 48 | + required: true |
| 49 | + default: 'main.zip' |
| 50 | + type: string |
| 51 | + parameter-overrides: |
| 52 | + description: 'The parameters to override in the stack inputs. You can pass a comma-delimited list or a file URL. The comma-delimited list has each entry formatted as <ParameterName>=<ParameterValue> or <ParameterName>="<ParameterValue>,<ParameterValue>".' |
| 53 | + required: false |
| 54 | + type: string |
| 55 | + secrets: |
| 56 | + AWS_ACCESS_KEY_ID: |
| 57 | + required: false |
| 58 | + description: 'AWS Access Key ID to install AWS CLI.' |
| 59 | + AWS_SECRET_ACCESS_KEY: |
| 60 | + required: false |
| 61 | + description: 'AWS Secret access key to install AWS CLI' |
| 62 | + AWS_SESSION_TOKEN: |
| 63 | + required: false |
| 64 | + description: 'AWS Session Token to install AWS CLI' |
| 65 | + ROLE-TO-ASSUME: |
| 66 | + required: false |
| 67 | + description: 'AWS Role ARN defined' |
| 68 | + GITHUB: |
| 69 | + required: false |
| 70 | + description: 'GitHub token' |
| 71 | + |
| 72 | +jobs: |
| 73 | + deploy-cf-stack: |
| 74 | + runs-on: ubuntu-latest |
| 75 | + |
| 76 | + steps: |
| 77 | + - name: Checkout code from master branch |
| 78 | + uses: actions/checkout@v2 |
| 79 | + |
| 80 | + - name: Checkout code from another Repo |
| 81 | + uses: actions/checkout@v4 |
| 82 | + with: |
| 83 | + repository: ${{ inputs.organization-name }}/${{ inputs.GitHub-repo-name }} |
| 84 | + ref: ${{ inputs.GitHub-branch }} |
| 85 | + token: ${{ secrets.GITHUB }} |
| 86 | + path: ${{ inputs.GitHub-repo-name }} |
| 87 | + |
| 88 | + - name: Configure AWS Credentials |
| 89 | + uses: aws-actions/configure-aws-credentials@v4 |
| 90 | + with: |
| 91 | + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID}} |
| 92 | + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 93 | + aws-session-token: ${{ secrets.AWS_SESSION_TOKEN }} |
| 94 | + aws-region: ${{ inputs.aws-region }} |
| 95 | + role-to-assume: ${{ inputs.ROLE-TO-ASSUME }} |
| 96 | + |
| 97 | + - name: Src folder code convert into zip and upload to S3 |
| 98 | + run: | |
| 99 | + cd ${{ inputs.GitHub-repo-name }}/${{ inputs.code-folder }} |
| 100 | + find . -maxdepth 1 -type f -exec zip ${{inputs.zip-file-name}} {} + |
| 101 | + run: | |
| 102 | + aws s3 cp ${{inputs.zip-file-name}} s3://${{ inputs.s3-bucket }}/${{ inputs.bucket-prefix }}/ |
| 103 | +
|
| 104 | + - name: Deploy cloudformation stack using template |
| 105 | + uses: aws-actions/aws-cloudformation-github-deploy@v1 |
| 106 | + with: |
| 107 | + name: ${{ inputs.stack-name }} |
| 108 | + template: ${{ inputs.template-path }} |
| 109 | + no-fail-on-empty-changeset: "1" |
| 110 | + parameter-overrides: ${{ inputs.parameter-overrides}} |
| 111 | +... |
0 commit comments