Wednesday, 30 September 2020

AWS code pipeline with S3 and Github connection

 AWS code pipeline

is a fully managed continuous delivery service that helps you to automate your release pipelines for fast and reliable application and infrastructure updates.
Automates the build,test and deploy phases of release process every time there is a change in code based on release model you defined.
This enables you to every time you deliver features and updates of app.
We can easily integrate AWS services such as GitHub or with your custom plugin.

First Host a static website on AWS S3.

Create a bucket with name 
Click on "Properties" tab after selecting on Bucket.

Click on static website hosting



Make a note of End point and click "Save".
Edit the block public access and enable public access , so that you can access this bucket outside.



Click "Save"

Click "confirm".

Add a bucket policy that your content in the bucket will be publicly available
Bucket policy:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "PublicReadGetObject",
            "Effect": "Allow",
            "Principal": "*",
            "Action": [
                "s3:GetObject"
            ],
            "Resource": [
                "arn:aws:s3:::mywebsite3009/*"
            ]
        }
    ]
}

Click "save"

you can ignore the following warning message if you would like to give access to the public.

Create "entry.html" with following content and upload the same to the created bucket.

entry.html:
<html>
<head>
    <title>My static Website Home Page</title>
</head>
<body>
  <h1>Welcome to my sample website</h1>
  <p>Am hosted on Amazon S3!</p>
</body>
</html>

Upload to the S3 bucket

Now you can copy the endpoint and paste it in the browser.

In my case the below is the figure .




We have now successfully hosted static website on S3.

Now we can select "codepipeline" under AWS services

 


Enter the pipeline name and accept the default values as below and select "Next".

Select "Github" as a source and click on "connect github"

Give your Github account name and select the repository name.

click on "install" then select "connect".


Then select "Next"

For now you can skip build stage.

Under "Deploy" select below values.



Select "Next" and review the details and select "create pipeline"

Now we have created successfully created pipeline.



Change something in "my-app" source code and check the git status.



and push the changes to github.


In another way 

you can have same website files which are uploaded to S3 and github will be same.
So that when you change the code of your website , it automatically reflect the change when you push.

Since have my Java project connected with S3 via pipeline, when you push the changes of your updated java file to github. the updated file will be shown under S3.



Now you can open sample.java , it will be shown as we have updated as below

Sample.java:
public class sample {

public static void main(String args[]){
System.out.println("Thiis is my app which is created in pipeline");
}

}

This is how codepipeline will work with static website, java project and github changes.





Thank you for reading.

No comments:

Post a Comment