Creating the web server CloudFormation template

Now we have our Ansible playbook ready, we are going to create our CloudFormation template using troposphere.

We are going to start by duplicating the troposphere script we created for Jenkins earlier in the chapter:

$ cd EffectiveDevOpsTemplates
$ cp jenkins-cf-template.py nodeserver-cf-template.py

We are going to edit the file nodeserver-cf-template.py and make the following changes:

We will first change the Application name and port by updating the variables as follows:

ApplicationName = "nodeserver" 
ApplicationPort = "3000" 

In addition, our instances will need to download files from S3. In order to allow for that to happen, we will replace the policy that allowed CodePipeline on our Jenkins instance with a policy to allow S3. Edit the policy called AllowCodePipeline and update its name and action.

Above the instantiation of our instance, add a new IAM policy resource as follows:

t.add_resource(IAMPolicy( 
    "Policy", 
    PolicyName="AllowS3", 
    PolicyDocument=Policy( 
        Statement=[ 
            Statement( 
                Effect=Allow, 
                Action=[Action("s3", "*")], 
                Resource=["*"]) 
        ] 
    ), 
    Roles=[Ref("Role")] 
)) 

This new script should look like this: http://bit.ly/2uDtR6g.

The new script is ready; we can save it and generate the CloudFormation template as follows:

$ git add nodeserver-cf-template.py 
$ git commit -m "Adding node server troposhere script"
$ git push
$ python nodeserver-cf-template.py > nodeserver-cf.template
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset