Part 2: Pipeline fun with AWS
Tags: cicd, automation, devtools, codedeploy
Published: 2023-08-17 21:35:53

## **STEP 3**
Welcome back techies to Part 2 of Pipelines Galore! We are going to be diving into the creation of our code pipeline, retrieving our region ID & IAM creds, along with taking it up a notch with additional validation testing. If you have not reviewed [Part 1](https://dev.to/khenry/part-1-pipeline-fun-with-aws-18ll) of this tutorial, please take the time to do so now so that you’re able to follow along as we wrap things up!

So we’ve verified that we have successfully created our Secret via Secrets Manager, as well as generated a net-new KMS Customer-managed key. To ensure we have the correct region ID and IAM role (these will be needed for the pipeline), let’s run the following commands:

```
aws configure get region
aws iam get-role --role-name <rolename>
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d27on6uq1yyb5yi31wth.png)

**Please note that my role also includes a policy that has permissions for Elastic Beanstalk, CloudWatch, SQS, and X-Ray**

(1) We will now begin with the creation of our Pipeline, which will **ONLY** include a Source & Deploy phase, though production pipelines **_will normally have a Build and Test phase_** included as well. There are two ways that you can create your pipeline: Use a json file with the specific parameters and run the `aws codepipeline create-pipeline --cli-input-json file://pipeline.json`​​ command once done with your file, OR via the Console, as shown below:
- In the Console, Navigate to CodePipeline and select “Create Pipeline”
- Give your pipeline a name and select an existing role or create a new role
- For the Source stage, select your specific provider
- SKIP the Build stage
- For the Deploy stage, add your Elastic Beanstalk details
- Click “Create Pipeline”, which should take a few minutes to generate

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ap107aw04rc2izj116vu.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6nhmcwdxxqyf8r9crooe.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m6rj4lkxtuw0v8r0ig44.png)

**If you'd like to test this out using the CLI instead, feel free to use this JSON sample to serve as a guide for your pipeline**:

```
{
    "pipeline": {
      "name": "yourpipelinename",
      "roleArn": "arn:aws:iam::1234567890:role/youriamrole",
      "artifactStore": {
        "type": "S3",
        "location": "yourbucketlocation"
      },
      "stages": [
        {
          "name": "Source",
          "actions": [
            {
              "name": "SourceAction",
              "actionTypeId": {
                "category": "Source",
                "owner": "AWS",
                "provider": "yourprovider",
                "version": "1"
              },
              "configuration": {
                "RepositoryName": "yourrepo",
                "BranchName": "master"
              },
              "outputArtifacts": [
                {
                  "name": "yourinput"
                }
              ],
              "runOrder": 1
            }
          ]
        },
        {
          "name": "Deploy",
          "actions": [
            {
              "name": "Deploy",
              "actionTypeId": {
                "category": "Deploy",
                "owner": "AWS",
                "provider": "Elastic Beanstalk",
                "version": "1"
              },
              "configuration": {
                "ApplicationName": "yourinput",
                "EnvironmentName": "yourinput"
              },
              "inputArtifacts": [
                {
                  "name": "yourinput"
                }
              ],
              "runOrder": 1
            }
          ]
        }
      ]
    }
  }
```

(2) We can verify that our pipeline and deployment were successful by visiting CodePipeline & our Elastic Beanstalk domain, as seen below:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pf16qfn28aqgol2hwjwq.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6wg447yky0zx9ae9at2o.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i0v2oervofn2u8c1q9gy.png)

(3) Now, we can take this up a notch by modifying one of the files created earlier, committing a new change, and then verifying that we can reach our previous Elastic Beanstalk domain, in which we should see the newly created changes. We’ll now push our newly updated files to the repo by using the following git commands as before:

```
git add .
git commit -m "Commit message"
git push origin master
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jaye2awqk41gjlqyod19.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rq6c5frkgp6v2ezp0nvc.png)

(4) If you check the screenshots below, you'll notice that our changes to the index.html file were successful, and we also have some neat metrics that are shown with CloudWatch as well:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ilbrivwntsl9icy9hjxp.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cvhjv23xtvpfvfruz0cx.png)

And that just about wraps it up for this two-part tutorial! I hope you have enjoyed creating your very first pipeline if you're net-new to AWS CodePipeline. Remember, there are _**multiple**_ ways that you can create a pipeline, and this tutorial just walked through one approach. Stay tuned for more tutorials that are coming your way! Follow me on [LinkedIn](https://www.linkedin.com/in/katoria-henry-2018/) to be on the lookout for new blogs.