-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlong-running-stack.yaml
More file actions
81 lines (70 loc) · 2.38 KB
/
long-running-stack.yaml
File metadata and controls
81 lines (70 loc) · 2.38 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
AWSTemplateFormatVersion: '2010-09-09'
Description: Test template that takes ~70 minutes to create
Parameters:
DelaySeconds:
Type: Number
Default: 840
Description: Seconds each resource waits (840 = 14 minutes, max for Lambda timeout buffer)
LambdaRoleArn:
Type: AWS::SSM::Parameter::Value<String>
Default: /test/long-running-lambda-role-arn
Resources:
DelayFunction:
Type: AWS::Lambda::Function
Properties:
Runtime: python3.12
Handler: index.handler
Role: !Ref LambdaRoleArn
Timeout: 900
Code:
ZipFile: |
import time
import cfnresponse
def handler(event, context):
try:
if event['RequestType'] == 'Delete':
cfnresponse.send(event, context, cfnresponse.SUCCESS, {})
return
delay_seconds = int(event['ResourceProperties']['DelaySeconds'])
print(f"Sleeping for {delay_seconds} seconds...")
time.sleep(delay_seconds)
print("Done sleeping")
cfnresponse.send(event, context, cfnresponse.SUCCESS,
{'Message': f'Waited {delay_seconds} seconds'})
except Exception as e:
print(f"Error: {str(e)}")
cfnresponse.send(event, context, cfnresponse.FAILED, {'Error': str(e)})
Delay1:
Type: AWS::CloudFormation::CustomResource
Properties:
ServiceToken: !GetAtt DelayFunction.Arn
DelaySeconds: !Ref DelaySeconds
Delay2:
Type: AWS::CloudFormation::CustomResource
DependsOn: Delay1
Properties:
ServiceToken: !GetAtt DelayFunction.Arn
DelaySeconds: !Ref DelaySeconds
Delay3:
Type: AWS::CloudFormation::CustomResource
DependsOn: Delay2
Properties:
ServiceToken: !GetAtt DelayFunction.Arn
DelaySeconds: !Ref DelaySeconds
Delay4:
Type: AWS::CloudFormation::CustomResource
DependsOn: Delay3
Properties:
ServiceToken: !GetAtt DelayFunction.Arn
DelaySeconds: !Ref DelaySeconds
Delay5:
Type: AWS::CloudFormation::CustomResource
DependsOn: Delay4
Properties:
ServiceToken: !GetAtt DelayFunction.Arn
DelaySeconds: !Ref DelaySeconds
Outputs:
DelaySecondsPerResource:
Value: !Ref DelaySeconds
TotalResources:
Value: 5