Skip to content

Instantly share code, notes, and snippets.

@nivleshc
nivleshc / blog-create-and-test-evergreen-golden-amis-codebuildfiles-cfn-test-golden-ami.yaml
Created Sep 11, 2022
This gist contains the AWS CloudFormation template that will be used to provision the test Amazon EC2 instance. The file is in the CodeBuildFiles folder in the blog-create-and-test-evergreen-golden-amis repository.
View blog-create-and-test-evergreen-golden-amis-codebuildfiles-cfn-test-golden-ami.yaml
AWSTemplateFormatVersion: 2010-09-09
Parameters:
FilenameSuffix:
Type: String
Description: Suffix used for report filename
InstanceType:
Type: String
Default: t3.micro
Description: Enter Instance size. Default is t3.micro
AmiId:
@nivleshc
nivleshc / blog-create-and-test-evergreen-golden-amis-codebuildfiles-test_golden_ami.rb
Created Sep 11, 2022
This gist contains the Chef Inspec controls file that will be used to test the golden AMI. The file is in the CodeBuildFiles folder in the blog-create-and-test-evergreen-golden-amis repository.
View blog-create-and-test-evergreen-golden-amis-codebuildfiles-test_golden_ami.rb
title "Check Golden AMI customisations and package installations"
control "Check customisations to motd"
control "Check Chef Inspec installed version is 5.18.14" do
desc "Validate that Chef Inspec version 5.18.14 is installed for ec2-user"
describe command('sudo -u ec2-user -i /opt/inspec/bin/inspec --version') do
its('stdout') { should include('5.18.14') }
end
end
@nivleshc
nivleshc / blog-create-and-test-evergreen-golden-amis-codebuildfiles-buildspec_test.yaml
Created Sep 11, 2022
This gist contains the test AWS CodeBuild project's buildspec file, which is in the CodeBuildFiles folder in the blog-create-and-test-evergreen-golden-amis repository.
View blog-create-and-test-evergreen-golden-amis-codebuildfiles-buildspec_test.yaml
version: 0.2
phases:
pre_build:
commands:
- echo "Test Pipeline:Phase:pre_build"
build:
commands:
- echo "Test Pipeline:Phase:build"
- time_now=$(date +%Y%m%dT%H%M%S)
@nivleshc
nivleshc / blog-create-and-test-evergreen-golden-amis-template-resources-testing-amazoneventbridge-rules.yaml
Created Sep 11, 2022
This gist contains the code for the Amazon EventBridge rules for the test AWS CodeBuild project. The code is in the Resources section of template.yaml in the blog-create-and-test-evergreen-golden-amis repository.
View blog-create-and-test-evergreen-golden-amis-template-resources-testing-amazoneventbridge-rules.yaml
# This is the Amazon EventBridge rule to send notifications via the Amazon SNS Topic when the AWS CodeBuild project for testing the Golden AMI is successful
EventBridgeRuleForCodeBuildForTestingSuccess:
Type: AWS::Events::Rule
Properties:
Description: This Amazon EventBridge rule will monitor and send notifications when the AWS CodeBuild project for testing the Golden AMI is successful
EventBusName: default
EventPattern:
source:
- aws.codebuild
detail-type:
@nivleshc
nivleshc / blog-create-and-test-evergreen-golden-amis-template-resources-codepipeline-test-stage.yaml
Created Sep 11, 2022
This gist contains the code for the test stage of the AWS CodePipeline pipeline, which is in the Resources section of template.yaml in the blog-create-and-test-evergreen-golden-amis repository.
View blog-create-and-test-evergreen-golden-amis-template-resources-codepipeline-test-stage.yaml
-
Name: Test
Actions:
-
Name: Test
ActionTypeId:
Category: Test
Owner: AWS
Provider: CodeBuild
Version: 1
@nivleshc
nivleshc / blog-create-and-test-evergreen-golden-amis-template-resources-testing-awscodebuildproject.yaml
Created Sep 11, 2022
This gist contains the code for the testing AWS CodeBuild project, which has been added to the Resources section of template.yaml in the blog-create-and-test-evergreen-golden-amis repository.
View blog-create-and-test-evergreen-golden-amis-template-resources-testing-awscodebuildproject.yaml
# this is the AWS CodeBuild project for testing the golden image
EvergreenAMICodeBuildProjectForTesting:
Type: AWS::CodeBuild::Project
Properties:
Artifacts:
Type: NO_ARTIFACTS
BadgeEnabled: false
Description: AWS CodeBuild project to test the Evergreen AMI that has been built.
Environment:
ComputeType: BUILD_GENERAL1_SMALL
@nivleshc
nivleshc / blog-create-and-test-evergreen-golden-amis-template-parameters.yaml
Created Sep 11, 2022
This gist contains the additional parameters that have been added to the Parameters section of the file template.yaml in the blog-create-and-test-evergreen-golden-amis repository.
View blog-create-and-test-evergreen-golden-amis-template-parameters.yaml
TestSubnetId:
Type: String
Description: This is the subnet where the Test EC2 instance will be created. This EC2 instance will be created using the newly created Golden AMI.
TestSecurityGroupId:
Type: String
Description: This is the id of the security group that will be attached to the test EC2 instance. This EC2 instance will created using the newly created Golden AMI.
TestEC2InstanceProfile:
Type: String
@nivleshc
nivleshc / blog-create-evergreen-golden-amis-customise_and_install_packages.sh
Created Aug 22, 2022
This gist contains the contents of customise_and_install_packages.sh from the blog-create-evergreen-golden-amis repository.
View blog-create-evergreen-golden-amis-customise_and_install_packages.sh
#!/bin/bash
set -ex
sudo yum update -y
sudo /usr/sbin/update-motd --disable
echo 'No unauthorized access permitted' | sudo tee /etc/motd
sudo rm /etc/issue
sudo ln -s /etc/motd /etc/issue
sudo yum install -y elinks screen
sudo yum install git -y
@nivleshc
nivleshc / blog-create-evergreen-golden-amis-template-outputs.yaml
Created Aug 22, 2022
This gist contains the Outputs section of template.yaml from the blog-create-evergreen-golden-amis repository.
View blog-create-evergreen-golden-amis-template-outputs.yaml
Outputs:
BaseAmiSSMParameterName:
Description: The Base AMI SSM Parameter Store Parameter Name.
Value: !Ref BaseAmiSSMParameterName
GoldenAmiSSMParameterName:
Description: The Golden AMI SSM Parameter Store Parameter Name.
Value: !Ref GoldenAmiSSMParameterName
CodeCommitRepoName:
Description: The name of the AWS CodeCommit Repository.
Value: !Ref CodeCommitRepoName
@nivleshc
nivleshc / blog-create-evergreen-golden-amis-template-resources-amazoneventbridgerule-detect-failed-codebuild.yaml
Created Aug 22, 2022
This gist contains the Resources section of template.yaml from the blog-create-evergreen-golden-amis repository. It shows the Amazon EventBridge rule to detect stopped or failed AWS CodeBuild builds.
View blog-create-evergreen-golden-amis-template-resources-amazoneventbridgerule-detect-failed-codebuild.yaml
EventBridgeRuleForCodeBuildNonSuccess:
Type: AWS::Events::Rule
Properties:
Description: This Amazon EventBridge rule will monitor and send notifications for all Evergreen AMI CodeBuild project state changes except for SUCCEEDED.
EventBusName: default
EventPattern:
source:
- aws.codebuild
detail-type:
- CodeBuild Build State Change