Skip to content

Commit f5ad4a6

Browse files
committed
fix: Address PR review comments
- Scope ecs:RunTask to specific task definitions instead of wildcard - Scope ecs:DescribeTasks to cluster tasks - Scope CheckpointDurableExecutions to specific function with durable-execution/* path - Fix directory name in README to lambda-ecs-durable-python-sam - Add expected test output for sync and callback patterns - Lowercase durable functions throughout docs - Add LinkedIn profile - Tested: both sync and callback patterns verified in CloudShell
1 parent 2dff793 commit f5ad4a6

3 files changed

Lines changed: 21 additions & 14 deletions

File tree

lambda-ecs-durable-python-sam/README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Lambda Durable Functions to Amazon ECS with Python
1+
# AWS Lambda durable functions to Amazon ECS with Python
22

33
This pattern demonstrates how to invoke Amazon ECS tasks from AWS Lambda durable functions using Python. The workflow starts an ECS task, waits for a callback, and resumes based on the task result while maintaining state across the pause/resume cycle.
44

@@ -23,7 +23,7 @@ Important: this application uses various AWS services and there are costs associ
2323
```
2424
1. Change directory to the pattern directory:
2525
```
26-
cd lambda-ecs-python-sam
26+
cd lambda-ecs-durable-python-sam
2727
```
2828
1. From the command line, use AWS SAM to build the application:
2929
```
@@ -94,13 +94,14 @@ aws lambda invoke \
9494
--payload '{"message": "Hello from sync pattern", "processingTime": 10}' \
9595
response.json
9696

97-
# Monitor Lambda logs
98-
aws logs tail /aws/lambda/$SYNC_FUNCTION --follow
99-
10097
# Monitor ECS task logs
10198
aws logs tail /ecs/$STACK_NAME --follow
10299
```
103100

101+
A successful sync test shows these log messages:
102+
- ECS task logs: `[SYNC] Completed: {"status": "success", ...}`
103+
- Lambda logs: `Durable execution completed` with the ECS task result
104+
104105
### Test Callback Pattern
105106

106107
```bash
@@ -119,7 +120,10 @@ aws logs tail /aws/lambda/$CALLBACK_FUNCTION --follow
119120
aws logs tail /ecs/$STACK_NAME --follow
120121
```
121122

122-
Expected output: The Lambda function should complete and return the ECS task result. The logs should show the callback being received and the function resuming execution.
123+
A successful callback test shows these log messages:
124+
- Lambda logs: `Callback created` followed by `Waiting for callback from ECS task`
125+
- ECS task logs: `[CALLBACK] Success callback sent!`
126+
- Lambda logs: `Callback received` followed by `Durable execution completed` with the ECS task result
123127

124128
## Cleanup
125129

lambda-ecs-durable-python-sam/example-pattern.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"title": "AWS Lambda Durable Functions to Amazon ECS with Python",
3-
"description": "Invoke ECS tasks from Lambda Durable Functions with automatic checkpointing, state management, and resilient execution patterns",
3+
"description": "Invoke ECS tasks from Lambda durable functions with automatic checkpointing, state management, and resilient execution patterns",
44
"language": "Python",
55
"level": "300",
66
"framework": "SAM",
77
"introBox": {
88
"headline": "How it works",
99
"text": [
10-
"This pattern demonstrates AWS Lambda Durable Functions invoking Amazon ECS tasks with resilient, long-running execution capabilities:",
10+
"This pattern demonstrates AWS Lambda durable functions invoking Amazon ECS tasks with resilient, long-running execution capabilities:",
1111
"1. Durable Synchronous Pattern: Lambda uses checkpointed steps and durable waits to poll ECS task status. Can run for up to 1 year with automatic recovery from failures. No compute charges during wait periods.",
1212
"2. Durable Callback Pattern: Lambda uses checkpointed steps to reliably initiate ECS tasks. Each step (create record, start task, update status) is automatically checkpointed for guaranteed execution.",
1313
"The pattern uses the AWS Durable Execution SDK for Python, providing automatic state management, checkpoint-based recovery, and cost-effective long-running workflows. Includes inline Python code in ECS containers, VPC networking, and DynamoDB for callback tracking."
@@ -24,7 +24,7 @@
2424
"resources": {
2525
"bullets": [
2626
{
27-
"text": "Lambda Durable Functions",
27+
"text": "Lambda durable functions",
2828
"link": "https://docs.aws.amazon.com/lambda/latest/dg/durable-functions.html"
2929
},
3030
{
@@ -62,7 +62,7 @@
6262
"name": "Mian Tariq",
6363
"image": "",
6464
"bio": "Senior Delivery Consultant",
65-
"linkedin": ""
65+
"linkedin": "mian-tariq"
6666
}
6767
]
6868
}

lambda-ecs-durable-python-sam/template.yaml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
AWSTemplateFormatVersion: '2010-09-09'
22
Transform: AWS::Serverless-2016-10-31
33
Description: >
4-
Lambda Durable Functions to ECS with Python - Demonstrates durable execution patterns with ECS tasks
4+
Lambda durable functions to ECS with Python - Demonstrates durable execution patterns with ECS tasks
55
66
Parameters:
77
VpcCIDR:
@@ -315,8 +315,11 @@ Resources:
315315
- Effect: Allow
316316
Action:
317317
- ecs:RunTask
318+
Resource: !Ref SyncTaskDefinition
319+
- Effect: Allow
320+
Action:
318321
- ecs:DescribeTasks
319-
Resource: '*'
322+
Resource: !Sub 'arn:aws:ecs:${AWS::Region}:${AWS::AccountId}:task/${AWS::StackName}-cluster/*'
320323
- Effect: Allow
321324
Action:
322325
- iam:PassRole
@@ -327,7 +330,7 @@ Resources:
327330
Action:
328331
- lambda:CheckpointDurableExecutions
329332
- lambda:GetDurableExecutionState
330-
Resource: '*'
333+
Resource: !Sub 'arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${AWS::StackName}-sync-function:$LATEST/durable-execution/*'
331334

332335
# Lambda Function for Callback Pattern (Durable)
333336
CallbackLambdaFunction:
@@ -359,7 +362,7 @@ Resources:
359362
- Effect: Allow
360363
Action:
361364
- ecs:RunTask
362-
Resource: '*'
365+
Resource: !Ref CallbackTaskDefinition
363366
- Effect: Allow
364367
Action:
365368
- iam:PassRole

0 commit comments

Comments
 (0)