Skip to content

Commit 4b2d7af

Browse files
Unit 16, Unit 17: Add Hello World debugging layer and platform targeting fixes
- Unit 16: Platform targeting resolution for OpenTelemetry issues - Unit 17: Hello World debugging layer as implementation model - Unit 17.1: Optional CI/CD workflow with retry logic - Complete Hello World implementation with scripts and documentation - Platform-targeted dependency installation patterns - Function URL setup with proper permissions and retry logic
1 parent a84bb4c commit 4b2d7af

5,368 files changed

Lines changed: 1358043 additions & 422 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 314 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,314 @@
1+
# Hello World Debug Function Deployment Workflow
2+
# Optional infrastructure validation and debugging baseline
3+
# Follows same pattern as deploy-layer-based-infrastructure.yml
4+
5+
name: Deploy Hello World Debug Function
6+
7+
on:
8+
workflow_dispatch:
9+
inputs:
10+
action:
11+
description: 'Hello World deployment action'
12+
required: true
13+
type: choice
14+
options:
15+
- build-and-deploy
16+
- test-only
17+
- cleanup
18+
default: 'build-and-deploy'
19+
20+
confirm_deploy:
21+
description: 'Type "yes" to confirm deployment operations'
22+
required: false
23+
type: string
24+
default: ''
25+
26+
test_mode:
27+
description: 'Testing mode for validation'
28+
required: false
29+
type: choice
30+
options:
31+
- comprehensive
32+
- quick
33+
- platform-only
34+
default: 'comprehensive'
35+
36+
env:
37+
AWS_DEFAULT_REGION: ${{ secrets.TF_VAR_aws_region }}
38+
TF_VAR_aws_region: ${{ secrets.TF_VAR_aws_region }}
39+
TF_VAR_environment: prod
40+
TF_VAR_project_name: coderipple
41+
42+
# Use same GitHub configuration as main workflow
43+
TF_VAR_github_repo_owner: ${{ secrets.TF_VAR_github_repo_owner }}
44+
TF_VAR_github_repo_name: ${{ secrets.TF_VAR_github_repo_name }}
45+
46+
jobs:
47+
deploy-helloworld:
48+
name: Deploy Hello World Debug Function
49+
runs-on: ubuntu-latest
50+
51+
steps:
52+
- name: Checkout repository
53+
uses: actions/checkout@v4
54+
with:
55+
fetch-depth: 2
56+
57+
- name: Set up Python 3.12
58+
uses: actions/setup-python@v5
59+
with:
60+
python-version: '3.12'
61+
62+
- name: Configure AWS credentials
63+
uses: aws-actions/configure-aws-credentials@v4
64+
with:
65+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
66+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
67+
aws-region: ${{ env.AWS_DEFAULT_REGION }}
68+
69+
- name: Install dependencies
70+
run: |
71+
pip install --upgrade pip
72+
pip install awscli jq
73+
sudo apt-get update && sudo apt-get install -y jq
74+
75+
- name: Build Hello World Layer
76+
if: ${{ github.event.inputs.action == 'build-and-deploy' }}
77+
run: |
78+
cd aws/helloworld
79+
echo "🚀 Building Hello World debugging layer..."
80+
./build_helloworld_layer.sh
81+
82+
- name: Package Hello World Function
83+
if: ${{ github.event.inputs.action == 'build-and-deploy' }}
84+
run: |
85+
cd aws/helloworld
86+
echo "📦 Packaging Hello World function..."
87+
./package_helloworld_function.sh
88+
89+
- name: Deploy Hello World Layer
90+
if: ${{ github.event.inputs.action == 'build-and-deploy' && github.event.inputs.confirm_deploy == 'yes' }}
91+
run: |
92+
cd aws/helloworld
93+
echo "🚀 Deploying Hello World layer..."
94+
./deploy_helloworld_layer.sh
95+
96+
- name: Deploy Hello World Function
97+
if: ${{ github.event.inputs.action == 'build-and-deploy' && github.event.inputs.confirm_deploy == 'yes' }}
98+
run: |
99+
cd aws/helloworld
100+
echo "🚀 Deploying Hello World function..."
101+
./deploy_helloworld_function.sh
102+
103+
- name: Setup Function URL with Permissions
104+
if: ${{ github.event.inputs.action == 'build-and-deploy' && github.event.inputs.confirm_deploy == 'yes' }}
105+
run: |
106+
echo "🔗 Setting up Function URL with proper permissions..."
107+
108+
# Create function URL if it doesn't exist
109+
aws lambda create-function-url-config \
110+
--function-name helloworld-debug \
111+
--cors '{"AllowCredentials": false, "AllowMethods": ["GET", "POST"], "AllowOrigins": ["*"]}' \
112+
--auth-type NONE \
113+
--region ${{ env.AWS_DEFAULT_REGION }} 2>/dev/null || echo "Function URL may already exist"
114+
115+
# Add required permissions for public access
116+
aws lambda add-permission \
117+
--function-name helloworld-debug \
118+
--statement-id FunctionURLAllowPublicAccess \
119+
--action lambda:InvokeFunctionUrl \
120+
--principal "*" \
121+
--function-url-auth-type NONE \
122+
--region ${{ env.AWS_DEFAULT_REGION }} 2>/dev/null || echo "Permission may already exist"
123+
124+
# Get and display the Function URL
125+
FUNCTION_URL=$(aws lambda get-function-url-config \
126+
--function-name helloworld-debug \
127+
--region ${{ env.AWS_DEFAULT_REGION }} \
128+
--query 'FunctionUrl' \
129+
--output text)
130+
131+
echo "✅ Function URL configured: $FUNCTION_URL"
132+
echo "🔑 Permissions added for public access"
133+
134+
- name: Test Hello World Function - Quick
135+
if: ${{ github.event.inputs.test_mode == 'quick' || github.event.inputs.action == 'test-only' }}
136+
run: |
137+
cd aws/helloworld
138+
echo "🧪 Quick test of Hello World function..."
139+
./test_helloworld.sh
140+
141+
- name: Test Hello World Function - Comprehensive
142+
if: ${{ github.event.inputs.test_mode == 'comprehensive' }}
143+
run: |
144+
cd aws/helloworld
145+
echo "🧪 Comprehensive testing of Hello World function..."
146+
./test_helloworld.sh
147+
148+
# Additional validation checks
149+
echo "✅ Performing comprehensive validation..."
150+
151+
aws lambda invoke \
152+
--function-name helloworld-debug \
153+
--payload '{"test": "ci-cd-comprehensive", "source": "github-actions"}' \
154+
--cli-binary-format raw-in-base64-out \
155+
--region ${{ env.AWS_DEFAULT_REGION }} \
156+
/tmp/helloworld_comprehensive.json
157+
158+
RESPONSE_BODY=$(cat /tmp/helloworld_comprehensive.json | jq -r '.body' | jq -r '.')
159+
160+
# Validate all key indicators
161+
echo "$RESPONSE_BODY" | jq -e '.message | contains("Hello World from CodeRipple Debug Layer")' > /dev/null
162+
echo "$RESPONSE_BODY" | jq -e '.strands_import == "SUCCESS"' > /dev/null
163+
echo "$RESPONSE_BODY" | jq -e '.platform_info.architecture == "x86_64"' > /dev/null
164+
echo "$RESPONSE_BODY" | jq -e '.platform_info.system == "Linux"' > /dev/null
165+
echo "$RESPONSE_BODY" | jq -e '.dependencies_status.boto3 == "SUCCESS"' > /dev/null
166+
167+
echo "✅ All comprehensive validation checks passed!"
168+
169+
- name: Test Hello World Function - Platform Only
170+
if: ${{ github.event.inputs.test_mode == 'platform-only' }}
171+
run: |
172+
cd aws/helloworld
173+
echo "🧪 Platform-specific testing..."
174+
175+
aws lambda invoke \
176+
--function-name helloworld-debug \
177+
--payload '{"test": "platform-validation"}' \
178+
--cli-binary-format raw-in-base64-out \
179+
--region ${{ env.AWS_DEFAULT_REGION }} \
180+
/tmp/helloworld_platform.json
181+
182+
RESPONSE_BODY=$(cat /tmp/helloworld_platform.json | jq -r '.body' | jq -r '.')
183+
184+
# Platform-specific validation
185+
ARCH=$(echo "$RESPONSE_BODY" | jq -r '.platform_info.architecture')
186+
SYSTEM=$(echo "$RESPONSE_BODY" | jq -r '.platform_info.system')
187+
188+
echo "Platform Architecture: $ARCH"
189+
echo "Platform System: $SYSTEM"
190+
191+
if [ "$ARCH" = "x86_64" ] && [ "$SYSTEM" = "Linux" ]; then
192+
echo "✅ Platform targeting verified: Linux x86_64"
193+
else
194+
echo "❌ Platform targeting failed: Expected Linux x86_64, got $SYSTEM $ARCH"
195+
exit 1
196+
fi
197+
198+
- name: Test Function URL with Retry Logic
199+
if: ${{ github.event.inputs.test_mode == 'comprehensive' }}
200+
run: |
201+
echo "🌐 Testing Function URL with retry logic..."
202+
203+
# Get the function URL from the deployed function
204+
echo "📡 Getting Function URL from deployed function..."
205+
FUNCTION_URL=$(aws lambda get-function-url-config \
206+
--function-name helloworld-debug \
207+
--region ${{ env.AWS_DEFAULT_REGION }} \
208+
--query 'FunctionUrl' \
209+
--output text 2>/dev/null || echo "")
210+
211+
if [ -z "$FUNCTION_URL" ] || [ "$FUNCTION_URL" = "None" ]; then
212+
echo "⚠️ No Function URL found, skipping URL test"
213+
exit 0
214+
fi
215+
216+
echo "🔗 Function URL: $FUNCTION_URL"
217+
218+
# Wait for initial propagation delay
219+
echo "⏳ Waiting 60 seconds for Function URL propagation..."
220+
sleep 60
221+
222+
# Retry logic: 3 attempts with 60-second delays
223+
SUCCESS=false
224+
for attempt in 1 2 3; do
225+
echo "🧪 Attempt $attempt/3: Testing Function URL..."
226+
227+
HTTP_STATUS=$(curl -s -o /tmp/curl_response_$attempt.json -w "%{http_code}" \
228+
-X POST "$FUNCTION_URL" \
229+
-H "Content-Type: application/json" \
230+
-d '{"test": "function-url-retry", "source": "ci-cd", "attempt": '$attempt'}' \
231+
--max-time 30)
232+
233+
echo "📊 HTTP Status: $HTTP_STATUS"
234+
235+
if [ "$HTTP_STATUS" = "200" ]; then
236+
echo "✅ Function URL responding successfully on attempt $attempt!"
237+
echo "📄 Response:"
238+
cat /tmp/curl_response_$attempt.json | jq '.'
239+
240+
# Validate the response contains expected content
241+
RESPONSE_BODY=$(cat /tmp/curl_response_$attempt.json | jq -r '.')
242+
if echo "$RESPONSE_BODY" | jq -e '.message | contains("Hello World from CodeRipple Debug Layer")' > /dev/null 2>&1; then
243+
echo "✅ Response validation passed!"
244+
SUCCESS=true
245+
break
246+
else
247+
echo "⚠️ Response validation failed, but HTTP 200 received"
248+
echo "📄 Response content:"
249+
cat /tmp/curl_response_$attempt.json
250+
fi
251+
else
252+
echo "❌ Function URL returned HTTP $HTTP_STATUS on attempt $attempt"
253+
echo "📄 Response content:"
254+
cat /tmp/curl_response_$attempt.json 2>/dev/null || echo "No response content"
255+
256+
if [ $attempt -lt 3 ]; then
257+
echo "⏳ Waiting 60 seconds before retry..."
258+
sleep 60
259+
fi
260+
fi
261+
done
262+
263+
if [ "$SUCCESS" = "true" ]; then
264+
echo "🎉 Function URL test completed successfully!"
265+
else
266+
echo "❌ Function URL test failed after 3 attempts"
267+
echo "💡 This may be due to:"
268+
echo " - Function URL permissions not set"
269+
echo " - Propagation delays (try manual test later)"
270+
echo " - Network connectivity issues"
271+
echo ""
272+
echo "🔧 Manual test command:"
273+
echo "curl -X POST \"$FUNCTION_URL\" -H \"Content-Type: application/json\" -d '{\"test\": \"manual\"}'"
274+
275+
# Don't fail the entire workflow for URL issues
276+
echo "⚠️ Continuing workflow (Function URL test is informational)"
277+
fi
278+
279+
- name: Cleanup Resources
280+
if: ${{ github.event.inputs.action == 'cleanup' && github.event.inputs.confirm_deploy == 'yes' }}
281+
run: |
282+
echo "🧹 Cleaning up Hello World resources..."
283+
284+
# Delete function
285+
aws lambda delete-function \
286+
--function-name helloworld-debug \
287+
--region ${{ env.AWS_DEFAULT_REGION }} || echo "Function not found"
288+
289+
# Delete function URL
290+
aws lambda delete-function-url-config \
291+
--function-name helloworld-debug \
292+
--region ${{ env.AWS_DEFAULT_REGION }} || echo "Function URL not found"
293+
294+
echo "✅ Cleanup completed"
295+
296+
- name: Summary Report
297+
if: always()
298+
run: |
299+
echo "📋 Hello World Debug Function Summary"
300+
echo "=================================="
301+
echo "Action: ${{ github.event.inputs.action }}"
302+
echo "Test Mode: ${{ github.event.inputs.test_mode }}"
303+
echo "Confirmed: ${{ github.event.inputs.confirm_deploy }}"
304+
echo "Region: ${{ env.AWS_DEFAULT_REGION }}"
305+
echo ""
306+
307+
if [ "${{ job.status }}" = "success" ]; then
308+
echo "✅ Hello World debugging function workflow completed successfully"
309+
echo "✅ Infrastructure validation baseline available"
310+
echo "✅ Platform targeting verified for CodeRipple deployment"
311+
else
312+
echo "❌ Hello World debugging function workflow failed"
313+
echo "📋 Check logs above for debugging information"
314+
fi

0 commit comments

Comments
 (0)