banner



How To Deploy Cf Template On Git.yml

At GitHub Universe 2019, we appear that nosotros open up sourced four new GitHub Deportment for Amazon ECS and ECR. Fast forrard to 2020 nosotros are expanding the number of available actions by releasing AWS CloudFormation Action for GitHub Actions.

This GitHub Action enables developers and cloud engineers to maintain their infrastructure as code in a AWS CloudFormation stack on their favorite open up source platform. The action uses AWS CloudFormation to continuously deploy updates to the described infrastructure.

In this article I will explain how to apply AWS CloudFormation Activeness for GitHub Actions past creating a new repository from the AWS CloudFormation Action for GitHub Deportment React Starter template. This template contains a React app, an AWS CloudFormation stack, and a GitHub Actions Workflow. The stack configures the cloned React app as a new app in the AWS Amplify Panel and uses the Amazon CloudFront Global Edge Network to distribute it globally in minutes.

Deploying a new app

Yous volition create a new repository on GitHub to play with AWS CloudFormation for GitHub Actions. To create this repository, visit the AWS CloudFormation Action for GitHub Deportment React Starter template. GitHub has this template characteristic to employ an existing repository as a template, so you and others tin can create a new repository with the same directory structure, branches, and files.

Click on Use this template to create a new repository from the template.

Select the "use this template" button to get started

Name the repository and add an optional description to it. The repository tin can be either public or private.

The AWS CloudFormation stack for your new React app is located in the stack.yml file at the root of the repository. Information technology configures your app as a new app in the AWS Dilate Panel.

The stack uses 3 AWS CloudFormation resources:

  • AWS::Amplify::App to create the app in the Amplify Console.
  • AWS::Amplify::Branch to configure a new branch within the app.
  • AWS::Amplify::Domain to connect a custom domain to your app.

The stack has required and optional parameters. It requires that yous provide the following:

  • Proper name to set the app name.
  • Repository to set the app repository.
  • Branch to set up the branch within the app.
  • OauthToken to configure the repository in the Amplify Console.

The GitHub Actions for AWS CloudFormation supports many input parameters. I is the parameter-overrides input, which lets you specify a list of comma-delimited parameters for the stack that sets the parameters for the AWS CloudFormation stack.

This input parameter is used at the deploy step of the main workflow. Y'all tin find this workflow divers in the .github/workflows/deploy.yamlfile in your repository. The workflow consists of five steps:

  1. Source code repository checkout.
  2. AWS credentials configuration.
  3. Environment variables configuration.
  4. Deployment to the AWS Dilate Console with AWS CloudFormation.
  5. Printing the configured custom domain.

Before moving to the deployment step, let's review the 2d step, which uses "Configure AWS Credentials" Activeness For GitHub Actions to configure your AWS credentials every bit environment variables for utilize in the other steps:

          - name: Configure AWS credentials       id: creds       uses: aws-actions/configure-aws-credentials@v1       with:         aws-admission-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}         aws-clandestine-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}         aws-region: ${{ github.result.inputs.region }}        

These credentials are stored in GitHub secrets. Secrets allow you store sensitive data in your repository. You must create an AWS account to retrieve and configure the needed secrets and to deploy the AWS CloudFormation stack. Follow the steps in the documentation if you do not take an account. Creating a new IAM user with simply programmatic access for the GitHub action is recommended.

If you have generated your access primal ID and secret admission key for this new user or your current user, you must configure these equally secrets for your repository. The settings are accessed via the Settings tab of your new repository.

The settings are accessed via the Settings tab of your new repository, on the top right side of the screen.

In the settings, select the Secrets choice and use the New secret push to create two secrets. AWS_ACCESS_KEY_ID contains the admission central ID and AWS_SECRET_ACCESS_KEY contains the secret access central of the user y'all are using to deploy the AWS CloudFormation stack in the steps.

In the settings select the Secrets option, which is above Actions at the bottom of the list on the left side of the screen, and and use the New secret button, which is located at the top right side of the screen, to create two secrets.

The AMPLIFY_TOKEN secret shown in the list of secrets is used at footstep four of the workflow. This step deploys the AWS CloudFormation stack with the AWS CloudFormation Action for GitHub Actions.

          - name: Deploy to Amplify Console with CloudFormation       id: amplify-stack       uses: aws-actions/aws-cloudformation-github-deploy@v1       with:         name: ${{ steps.env-name.outputs.environs }}         template: stack.yaml         no-fail-on-empty-changeset: "1"         parameter-overrides: >-           Name=${{ steps.env-proper name.outputs.environment }},           Repository=https://github.com/${{ github.repository }},           OauthToken=${{ secrets.AMPLIFY_TOKEN }},           Domain=${{ secrets.AMPLIFY_DOMAIN }}        

The AMPLIFY_TOKEN stores a personal access token for GitHub. Amplify Console uses the token to configure a webhook in your repository. This webhook is chosen whenever you push changes to your repository. It triggers the build pipeline in the AWS Amplify Console.

To create this personal access token, go your GitHub profile and select the Developer settings.

Developer settings option below Applications option at the bottom

In the developer settings, select Personal access token and select the Generate new token push to create a new token. You can proper noun this token Amplify Panel as shown in the following screenshot. Creating the token makes identifying and revoking access easy.

In the developer settings select Personal access token and block on the Generate new token button to create a new token. You can name this token Amplify Console as shown in the screenshot.

The token needs full control of private repository permissions.

The token needs full control of private repository permissions.

Re-create the token that is created and configure it as AMPLIFY_TOKEN in the repository secrets.

If you want to apply a custom domain for your app, you can configure this domain every bit an additional AMPLIFY_DOMAIN hugger-mugger in your repository. This is optional; the AWS Amplify Console makes your app available via a subdomain to the amplifyapp.com domain.

You are ready to deploy the AWS CloudFormation stack. The deployment is run past a transmission trigger, considering AWS Amplify itself configures a build pipeline for your project. That pipeline is run with every push to your repository. Whenever you want to update your stack, re-run the trigger.

Click on Actions in the new repository to see all configured GitHub Actions.

Click on Actions in new repository, select the failed build and click the Re-run jobs and select the Re-run all jobs option.

The sidebar shows all workflows; select the Deployworkload to run information technology in the adjacent step.

Deploy Workflow

Adjacent, click on theRun workflow drib-down. This opens a popover that lets you configure the parameters of this deployment. By default, the AWS CloudFormation stack is deployed to the the states-eastward-i region. You can change the setting at this step, if you desire to test this in a unlike region. Regardless of the region yous deploy this stack to, your app is served from the Amazon CloudFront Global Edge Network.

Select the run workflow option and run the workflow

When the build has finished, yous tin can access your new app in the AWS Management Console.

When the build has succeeded, you can access your new app in the AWS Management Console.

Select your new app; you lot created a new repository, so the proper name will exist different. Considering the build specs are in the dilate.yml file in the root of your project, y'all must manually trigger a build once.

Select the Run build button to trigger the build

Afterward the build process has finished, you lot can access your React application via the provided link.

Use the link shown in the console to access your app

Yous likewise can find the deployed AWS CloudFormation stack in the panel.

AWS CloudFormation console shows the stack

When y'all change the AWS CloudFormation stack in the chief branch of your repository, AWS CloudFormation Activity for GitHub Actions volition update your stack.

Past default, a deployment with an empty AWS CloudFormation modify set results in an error in the workflow. The no-neglect-on-empty-changeset input parameter allows you override this behavior, which the template y'all used here does. The GitHub repository shows the input parameters that are supported.

Summary

AWS CloudFormation Action for GitHub Actions is a powerful tool to bring together the open source platform and the cloud, which has the breadth of services and the deepest functionality within those services. In this tutorial, you have used infrastructure as lawmaking to brand an awarding available to a global audition.

Submit your feedback past opening issues, by pull requests, or by starring the GitHub repository. We cannot wait to see what great things yous build with it.

Acknowledgements

The code for the React app was created with the Create React App tool and is under the MIT license.

Feature paradigm via Pixabay.

How To Deploy Cf Template On Git.yml,

Source: https://aws.amazon.com/blogs/opensource/deploy-aws-cloudformation-stacks-with-github-actions/

Posted by: boydmixtiffinuel.blogspot.com

0 Response to "How To Deploy Cf Template On Git.yml"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel