@@ -32,42 +32,55 @@ func (rm *resourceManager) syncEventInvokeConfig(
32
32
exit := rlog .Trace ("rm.syncEventInvokeConfig" )
33
33
defer exit (err )
34
34
35
+ // Check if the user deleted the 'FunctionEventInvokeConfig' configuration
36
+ // If yes, delete FunctionEventInvokeConfig
37
+ if r .ko .Spec .FunctionEventInvokeConfig == nil {
38
+ input_delete := & svcsdk.DeleteFunctionEventInvokeConfigInput {
39
+ FunctionName : aws .String (* r .ko .Spec .FunctionName ),
40
+ Qualifier : aws .String (* r .ko .Spec .Name ),
41
+ }
42
+ _ , err = rm .sdkapi .DeleteFunctionEventInvokeConfigWithContext (ctx , input_delete )
43
+ rm .metrics .RecordAPICall ("DELETE" , "DeleteFunctionEventInvokeConfig" , err )
44
+ if err != nil {
45
+ return nil , err
46
+ }
47
+ return r , nil
48
+ }
49
+
35
50
dspec := r .ko .Spec
36
51
input := & svcsdk.PutFunctionEventInvokeConfigInput {
37
52
FunctionName : aws .String (* dspec .FunctionName ),
38
53
Qualifier : aws .String (* dspec .Name ),
39
54
}
40
55
41
- if r .ko .Spec .FunctionEventInvokeConfig != nil {
42
- if r .ko .Spec .FunctionEventInvokeConfig .DestinationConfig != nil {
43
- destinations := & svcsdk.DestinationConfig {}
44
- if r .ko .Spec .FunctionEventInvokeConfig .DestinationConfig .OnFailure != nil {
45
- destinations .OnFailure = & svcsdk.OnFailure {}
46
- if r .ko .Spec .FunctionEventInvokeConfig .DestinationConfig .OnFailure .Destination != nil {
47
- destinations .OnFailure .Destination = aws .String (* r .ko .Spec .FunctionEventInvokeConfig .DestinationConfig .OnFailure .Destination )
48
- }
49
- }
50
- if r .ko .Spec .FunctionEventInvokeConfig .DestinationConfig .OnSuccess != nil {
51
- destinations .OnSuccess = & svcsdk.OnSuccess {}
52
- if r .ko .Spec .FunctionEventInvokeConfig .DestinationConfig .OnSuccess .Destination != nil {
53
- destinations .OnSuccess .Destination = aws .String (* r .ko .Spec .FunctionEventInvokeConfig .DestinationConfig .OnSuccess .Destination )
54
- }
56
+ if dspec .FunctionEventInvokeConfig .DestinationConfig != nil {
57
+ destinations := & svcsdk.DestinationConfig {}
58
+ if dspec .FunctionEventInvokeConfig .DestinationConfig .OnFailure != nil {
59
+ destinations .OnFailure = & svcsdk.OnFailure {}
60
+ if dspec .FunctionEventInvokeConfig .DestinationConfig .OnFailure .Destination != nil {
61
+ destinations .OnFailure .Destination = aws .String (* dspec .FunctionEventInvokeConfig .DestinationConfig .OnFailure .Destination )
55
62
}
56
- input .DestinationConfig = destinations
57
- }
58
- if r .ko .Spec .FunctionEventInvokeConfig .MaximumEventAgeInSeconds != nil {
59
- input .MaximumEventAgeInSeconds = aws .Int64 (* r .ko .Spec .FunctionEventInvokeConfig .MaximumEventAgeInSeconds )
60
63
}
61
- if r .ko .Spec .FunctionEventInvokeConfig .MaximumRetryAttempts != nil {
62
- input .MaximumRetryAttempts = aws .Int64 (* r .ko .Spec .FunctionEventInvokeConfig .MaximumRetryAttempts )
64
+ if dspec .FunctionEventInvokeConfig .DestinationConfig .OnSuccess != nil {
65
+ destinations .OnSuccess = & svcsdk.OnSuccess {}
66
+ if dspec .FunctionEventInvokeConfig .DestinationConfig .OnSuccess .Destination != nil {
67
+ destinations .OnSuccess .Destination = aws .String (* dspec .FunctionEventInvokeConfig .DestinationConfig .OnSuccess .Destination )
68
+ }
63
69
}
70
+ input .DestinationConfig = destinations
71
+ }
72
+ if dspec .FunctionEventInvokeConfig .MaximumEventAgeInSeconds != nil {
73
+ input .MaximumEventAgeInSeconds = aws .Int64 (* dspec .FunctionEventInvokeConfig .MaximumEventAgeInSeconds )
74
+ }
75
+ if dspec .FunctionEventInvokeConfig .MaximumRetryAttempts != nil {
76
+ input .MaximumRetryAttempts = aws .Int64 (* dspec .FunctionEventInvokeConfig .MaximumRetryAttempts )
64
77
}
78
+
65
79
_ , err = rm .sdkapi .PutFunctionEventInvokeConfigWithContext (ctx , input )
66
80
rm .metrics .RecordAPICall ("UPDATE" , "SyncEventInvokeConfig" , err )
67
81
if err != nil {
68
82
return nil , err
69
83
}
70
-
71
84
return r , nil
72
85
}
73
86
@@ -104,7 +117,7 @@ func (rm *resourceManager) updateProvisionedConcurrency(
104
117
return nil
105
118
}
106
119
107
- func (rm * resourceManager ) getProvisionedConcurrencyConfig (
120
+ func (rm * resourceManager ) setProvisionedConcurrencyConfig (
108
121
ctx context.Context ,
109
122
ko * svcapitypes.Alias ,
110
123
) (err error ) {
@@ -132,7 +145,35 @@ func (rm *resourceManager) getProvisionedConcurrencyConfig(
132
145
return nil
133
146
}
134
147
135
- func (rm * resourceManager ) getFunctionEventInvokeConfig (
148
+ func (rm * resourceManager ) setFunctionEventInvokeConfigFromResponse (
149
+ ko * svcapitypes.Alias ,
150
+ getFunctionEventInvokeConfigOutput * svcsdk.GetFunctionEventInvokeConfigOutput ,
151
+ apiError error ,
152
+ ) (err error ) {
153
+
154
+ if apiError != nil {
155
+ if awserr , ok := ackerr .AWSError (apiError ); ok && (awserr .Code () == "EventInvokeConfigNotFoundException" || awserr .Code () == "ResourceNotFoundException" ) {
156
+ ko .Spec .FunctionEventInvokeConfig = nil
157
+ } else {
158
+ return apiError
159
+ }
160
+ } else {
161
+ cloudFunctionEventInvokeConfig := & svcapitypes.PutFunctionEventInvokeConfigInput {}
162
+ cloudFunctionEventInvokeConfig .DestinationConfig = & svcapitypes.DestinationConfig {}
163
+ cloudFunctionEventInvokeConfig .DestinationConfig .OnFailure = & svcapitypes.OnFailure {}
164
+ cloudFunctionEventInvokeConfig .DestinationConfig .OnSuccess = & svcapitypes.OnSuccess {}
165
+ cloudFunctionEventInvokeConfig .DestinationConfig .OnFailure .Destination = getFunctionEventInvokeConfigOutput .DestinationConfig .OnFailure .Destination
166
+ cloudFunctionEventInvokeConfig .DestinationConfig .OnSuccess .Destination = getFunctionEventInvokeConfigOutput .DestinationConfig .OnSuccess .Destination
167
+ cloudFunctionEventInvokeConfig .MaximumEventAgeInSeconds = getFunctionEventInvokeConfigOutput .MaximumEventAgeInSeconds
168
+ cloudFunctionEventInvokeConfig .MaximumRetryAttempts = getFunctionEventInvokeConfigOutput .MaximumRetryAttempts
169
+ ko .Spec .FunctionEventInvokeConfig = cloudFunctionEventInvokeConfig
170
+ }
171
+ return nil
172
+ }
173
+
174
+ // getFunctionEventInvokeConfig will describe the fields that are
175
+ // custom to the Alias resource
176
+ func (rm * resourceManager ) setFunctionEventInvokeConfig (
136
177
ctx context.Context ,
137
178
ko * svcapitypes.Alias ,
138
179
) (err error ) {
@@ -144,40 +185,11 @@ func (rm *resourceManager) getFunctionEventInvokeConfig(
144
185
Qualifier : ko .Spec .Name ,
145
186
},
146
187
)
147
-
148
188
rm .metrics .RecordAPICall ("GET" , "GetFunctionEventInvokeConfig" , err )
149
189
190
+ err = rm .setFunctionEventInvokeConfigFromResponse (ko , getFunctionEventInvokeConfigOutput , err )
150
191
if err != nil {
151
- if awserr , ok := ackerr .AWSError (err ); ok && (awserr .Code () == "EventInvokeConfigNotFoundException" || awserr .Code () == "ResourceNotFoundException" ) {
152
- ko .Spec .FunctionEventInvokeConfig = nil
153
- } else {
154
- return err
155
- }
156
- } else {
157
- if getFunctionEventInvokeConfigOutput .DestinationConfig != nil {
158
- if getFunctionEventInvokeConfigOutput .DestinationConfig .OnFailure != nil {
159
- if getFunctionEventInvokeConfigOutput .DestinationConfig .OnFailure .Destination != nil {
160
- ko .Spec .FunctionEventInvokeConfig .DestinationConfig .OnFailure .Destination = getFunctionEventInvokeConfigOutput .DestinationConfig .OnFailure .Destination
161
- }
162
- }
163
- if getFunctionEventInvokeConfigOutput .DestinationConfig .OnSuccess != nil {
164
- if getFunctionEventInvokeConfigOutput .DestinationConfig .OnSuccess .Destination != nil {
165
- ko .Spec .FunctionEventInvokeConfig .DestinationConfig .OnSuccess .Destination = getFunctionEventInvokeConfigOutput .DestinationConfig .OnSuccess .Destination
166
- }
167
- }
168
- } else {
169
- ko .Spec .FunctionEventInvokeConfig .DestinationConfig = nil
170
- }
171
- if getFunctionEventInvokeConfigOutput .MaximumEventAgeInSeconds != nil {
172
- ko .Spec .FunctionEventInvokeConfig .MaximumEventAgeInSeconds = getFunctionEventInvokeConfigOutput .MaximumEventAgeInSeconds
173
- } else {
174
- ko .Spec .FunctionEventInvokeConfig .MaximumEventAgeInSeconds = nil
175
- }
176
- if getFunctionEventInvokeConfigOutput .DestinationConfig != nil {
177
- ko .Spec .FunctionEventInvokeConfig .MaximumRetryAttempts = getFunctionEventInvokeConfigOutput .MaximumRetryAttempts
178
- } else {
179
- ko .Spec .FunctionEventInvokeConfig .MaximumRetryAttempts = nil
180
- }
192
+ return err
181
193
}
182
194
183
195
return nil
@@ -191,14 +203,16 @@ func (rm *resourceManager) setResourceAdditionalFields(
191
203
exit := rlog .Trace ("rm.setResourceAdditionalFields" )
192
204
defer exit (err )
193
205
194
- eic_err := rm .getFunctionEventInvokeConfig (ctx , ko )
195
- if eic_err != nil {
196
- return eic_err
206
+ // To set Asynchronous Invocations for the function's alias
207
+ err = rm .setFunctionEventInvokeConfig (ctx , ko )
208
+ if err != nil {
209
+ return err
197
210
}
198
211
199
- pc_err := rm .getProvisionedConcurrencyConfig (ctx , ko )
200
- if pc_err != nil {
201
- return pc_err
212
+ // To set Provisioned Concurrency for the function's alias
213
+ err = rm .setProvisionedConcurrencyConfig (ctx , ko )
214
+ if err != nil {
215
+ return err
202
216
}
203
217
204
218
return nil
0 commit comments