-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·124 lines (108 loc) · 4.4 KB
/
Copy pathdeploy.sh
File metadata and controls
executable file
·124 lines (108 loc) · 4.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/bash
# AWS DevOps Agent Demo - Deployment Script
set -e
STACK_NAME="unicorn-rentals"
ENVIRONMENT="prod"
WEBHOOK_URL="${DEVOPS_AGENT_WEBHOOK_URL:-}"
WEBHOOK_SECRET="${DEVOPS_AGENT_WEBHOOK_SECRET:-}"
echo "🚀 Deploying Unicorn Rentals Environment"
echo "================================================"
# Check if AWS CLI is configured
if ! aws sts get-caller-identity > /dev/null 2>&1; then
echo "❌ AWS CLI not configured. Please run 'aws configure' first."
exit 1
fi
echo "✅ AWS CLI configured"
# Build parameters list
PARAMS="ParameterKey=Environment,ParameterValue=$ENVIRONMENT"
if [ -n "$WEBHOOK_URL" ] && [ -n "$WEBHOOK_SECRET" ]; then
PARAMS="$PARAMS ParameterKey=DevOpsAgentWebhookUrl,ParameterValue=$WEBHOOK_URL ParameterKey=DevOpsAgentWebhookSecret,ParameterValue=$WEBHOOK_SECRET"
echo "🔗 Webhook integration enabled"
else
echo "ℹ️ No webhook configured (set DEVOPS_AGENT_WEBHOOK_URL and DEVOPS_AGENT_WEBHOOK_SECRET to enable)"
fi
# Check if stack exists and its status
STACK_STATUS=""
if aws cloudformation describe-stacks --stack-name $STACK_NAME > /dev/null 2>&1; then
STACK_STATUS=$(aws cloudformation describe-stacks \
--stack-name $STACK_NAME \
--query 'Stacks[0].StackStatus' \
--output text)
echo "📋 Stack exists with status: $STACK_STATUS"
fi
# Handle different stack states
if [ "$STACK_STATUS" = "CREATE_FAILED" ] || [ "$STACK_STATUS" = "ROLLBACK_COMPLETE" ]; then
echo "🗑️ Deleting failed stack..."
aws cloudformation delete-stack --stack-name $STACK_NAME
echo "⏳ Waiting for stack deletion..."
aws cloudformation wait stack-delete-complete --stack-name $STACK_NAME
STACK_STATUS=""
fi
if [ -z "$STACK_STATUS" ]; then
# Create new stack
echo "📦 Creating CloudFormation stack..."
aws cloudformation create-stack \
--stack-name $STACK_NAME \
--template-body file://cloudformation-template.yaml \
--capabilities CAPABILITY_NAMED_IAM \
--parameters $PARAMS \
--tags Key=Purpose,Value=DevOpsAgent Key=Environment,Value=$ENVIRONMENT Key=auto-delete,Value=never Key=auto-stop,Value=no
echo "⏳ Waiting for stack creation to complete..."
aws cloudformation wait stack-create-complete --stack-name $STACK_NAME
else
# Update existing stack
echo "🔄 Updating existing CloudFormation stack..."
UPDATE_OUTPUT=$(aws cloudformation update-stack \
--stack-name $STACK_NAME \
--template-body file://cloudformation-template.yaml \
--capabilities CAPABILITY_NAMED_IAM \
--parameters $PARAMS 2>&1) || {
if echo "$UPDATE_OUTPUT" | grep -q "No updates are to be performed"; then
echo "✅ Stack is already up to date. No changes needed."
else
echo "❌ Stack update failed: $UPDATE_OUTPUT"
exit 1
fi
}
if echo "$UPDATE_OUTPUT" | grep -q "StackId"; then
echo "⏳ Waiting for stack update to complete..."
aws cloudformation wait stack-update-complete --stack-name $STACK_NAME
fi
fi
# Get outputs
echo "📋 Retrieving stack outputs..."
API_URL=$(aws cloudformation describe-stacks \
--stack-name $STACK_NAME \
--query 'Stacks[0].Outputs[?OutputKey==`ApiGatewayUrl`].OutputValue' \
--output text)
LAMBDA_NAME=$(aws cloudformation describe-stacks \
--stack-name $STACK_NAME \
--query 'Stacks[0].Outputs[?OutputKey==`LambdaFunctionName`].OutputValue' \
--output text)
TABLE_NAME=$(aws cloudformation describe-stacks \
--stack-name $STACK_NAME \
--query 'Stacks[0].Outputs[?OutputKey==`DynamoDBTableName`].OutputValue' \
--output text)
# Create environment file
cat > demo-environment.env << EOF
# Unicorn Rentals Environment Variables
export API_URL="$API_URL"
export LAMBDA_NAME="$LAMBDA_NAME"
export TABLE_NAME="$TABLE_NAME"
export STACK_NAME="$STACK_NAME"
EOF
echo "✅ Deployment complete!"
echo ""
echo "📊 Demo Environment Details:"
echo " Stack Name: $STACK_NAME"
echo " API URL: $API_URL"
echo " Lambda Function: $LAMBDA_NAME"
echo " DynamoDB Table: $TABLE_NAME"
echo ""
echo "🎯 Next Steps:"
echo " 1. Source environment: source demo-environment.env"
echo " 2. Install Python dependencies: pip install requests"
echo " 3. Run load generator: python continuous-load-generator.py --api-url \$API_URL --rps 15 --duration 10"
echo " 4. Monitor alarms and DevOps Agent investigations"
echo ""
echo "🧹 To cleanup: ./cleanup.sh"