Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BAU: Add script for running locally to deploy using the produced tempate #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions deployment/distributed-load-testing-params.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[
{
"ParameterKey": "AdminName",
"ParameterValue": "rms-codepipeline"
},
{
"ParameterKey": "AdminEmail",
"ParameterValue": "[email protected]"
},
{
"ParameterKey": "ExistingVPCId",
"ParameterValue": "vpc-6c1ebc09"
},
{
"ParameterKey": "ExistingSubnetA",
"ParameterValue": "subnet-5fd00b06"
},
{
"ParameterKey": "ExistingSubnetB",
"ParameterValue": "subnet-1527b970"
}
]
81 changes: 81 additions & 0 deletions deployment/run-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/env bash

set -e

export REGION=eu-west-1 # the AWS region to launch the solution (e.g. us-east-1)
export BUCKET_PREFIX=rms-aws-distributed-load-testing-bucket # prefix of the bucket name without the region code
export BUCKET_NAME=$BUCKET_PREFIX-$REGION # full bucket name where the code will reside
export SOLUTION_NAME=distributed-load-testing-on-aws
export VERSION=v1.0.0 # version number for the customized code
export PUBLIC_ECR_REGISTRY=public.ecr.aws/aws-solutions # replace with the container registry and image if you want to use a different container image
export PUBLIC_ECR_TAG=v3.2.5 # replace with the container image tag if you want to use a different container image

#./build-s3-dist.sh $BUCKET_PREFIX $SOLUTION_NAME $VERSION

echo "Checking to see if the $BUCKET_NAME bucket exists..."

if aws s3api head-bucket --bucket "$BUCKET_NAME" 2>/dev/null; then
echo "Found bucket"
else
echo "Could not find bucket, creating the initial bucket using the stack..."

aws cloudformation create-stack \
--stack-name rms-aws-distributed-load-testing-s3-deploy-stack \
--template-body "file://s3-deploy-stack.json" \
--capabilities CAPABILITY_IAM \
--role-arn arn:aws:iam::253011676286:role/rms-codepipeline-cloudformation-role \
--on-failure DELETE

echo "Waiting until bucket is created..."

NEXT_WAIT_TIME=0
until (( NEXT_WAIT_TIME == 10 )); do

if aws s3api head-bucket --bucket "$BUCKET_NAME" 2>/dev/null; then
NEXT_WAIT_TIME = 10
else
echo "Could not find bucket, sleeping for 30s"
NEXT_WAIT_TIME=$((NEXT_WAIT_TIME + 1))
sleep 30
fi

done
(( NEXT_WAIT_TIME < 10 ))

if aws s3api head-bucket --bucket "$BUCKET_NAME" 2>/dev/null; then
echo "Bucket created successfully"
else
echo "Could not find bucket, check the stack, exiting..."
exit 1
fi

fi

echo "Uploading the produced template to S3..."

aws s3 sync global-s3-assets s3://$BUCKET_NAME/$SOLUTION_NAME/$VERSION
aws s3 sync regional-s3-assets s3://$BUCKET_NAME/$SOLUTION_NAME/$VERSION

# template url is s3://rms-aws-distributed-load-testing-bucket-eu-west-1/rms-aws-distributed-load-testing/v1.0.0/distributed-load-testing-on-aws.template
# s3://$BUCKET_NAME/$SOLUTION_NAME/$VERSION/$SOLUTION_NAME.template

echo "Creating or updating stack based off of generated template..."
echo "Using template url: https://$BUCKET_NAME.s3.eu-west-1.amazonaws.com/$BUCKET_NAME/$SOLUTION_NAME/$VERSION/$SOLUTION_NAME.template"

if aws cloudformation describe-stacks --stack-name rms-aws-distributed-load-testing-stack &>/dev/null
then
aws cloudformation update-stack \
--stack-name rms-aws-distributed-load-testing-stack \
--template-url "https://$BUCKET_NAME.s3.eu-west-1.amazonaws.com/$SOLUTION_NAME/$VERSION/$SOLUTION_NAME.template" \
--parameters "file://distributed-load-testing-params.json" \
--capabilities CAPABILITY_IAM \
--role-arn arn:aws:iam::253011676286:role/rms-codepipeline-cloudformation-role
else
aws cloudformation create-stack \
--stack-name rms-aws-distributed-load-testing-stack \
--template-url "https://$BUCKET_NAME.s3.eu-west-1.amazonaws.com/$SOLUTION_NAME/$VERSION/$SOLUTION_NAME.template" \
--parameters "file://distributed-load-testing-params.json" \
--capabilities CAPABILITY_IAM \
--role-arn arn:aws:iam::253011676286:role/rms-codepipeline-cloudformation-role \
--on-failure DELETE
fi
39 changes: 39 additions & 0 deletions deployment/s3-deploy-stack.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"AWSTemplateFormatVersion": "2010-09-09",
"Parameters": {},
"Description": "AWS infrastructure for the Service",
"Resources": {
"DistributedLoadTestingDeployBucket": {
"Type": "AWS::S3::Bucket",
"Properties": {
"BucketName": "rms-aws-distributed-load-testing-bucket-eu-west-1",
"LifecycleConfiguration": {
"Rules": [
{
"ExpirationInDays": 30,
"Status": "Enabled"
}
]
},
"PublicAccessBlockConfiguration": {
"BlockPublicAcls": true,
"BlockPublicPolicy": true,
"IgnorePublicAcls": true,
"RestrictPublicBuckets": true
},
"Tags": [
{
"Key": "BBCComponent",
"Value": "rms-aws-distributed-load-testing"
},
{
"Key": "BBCProject",
"Value": "rmservices"
}
]
},
"UpdateReplacePolicy": "Retain",
"DeletionPolicy": "Retain"
}
}
}