@@ -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,36 @@ 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
+ // creating FunctionEventInvokeConfig object to store the values returned from `Get` call
162
+ cloudFunctionEventInvokeConfig := & svcapitypes.PutFunctionEventInvokeConfigInput {}
163
+ cloudFunctionEventInvokeConfig .DestinationConfig = & svcapitypes.DestinationConfig {}
164
+ cloudFunctionEventInvokeConfig .DestinationConfig .OnFailure = & svcapitypes.OnFailure {}
165
+ cloudFunctionEventInvokeConfig .DestinationConfig .OnSuccess = & svcapitypes.OnSuccess {}
166
+ cloudFunctionEventInvokeConfig .DestinationConfig .OnFailure .Destination = getFunctionEventInvokeConfigOutput .DestinationConfig .OnFailure .Destination
167
+ cloudFunctionEventInvokeConfig .DestinationConfig .OnSuccess .Destination = getFunctionEventInvokeConfigOutput .DestinationConfig .OnSuccess .Destination
168
+ cloudFunctionEventInvokeConfig .MaximumEventAgeInSeconds = getFunctionEventInvokeConfigOutput .MaximumEventAgeInSeconds
169
+ cloudFunctionEventInvokeConfig .MaximumRetryAttempts = getFunctionEventInvokeConfigOutput .MaximumRetryAttempts
170
+ ko .Spec .FunctionEventInvokeConfig = cloudFunctionEventInvokeConfig
171
+ }
172
+ return nil
173
+ }
174
+
175
+ // getFunctionEventInvokeConfig will describe the fields that are
176
+ // custom to the Alias resource
177
+ func (rm * resourceManager ) setFunctionEventInvokeConfig (
136
178
ctx context.Context ,
137
179
ko * svcapitypes.Alias ,
138
180
) (err error ) {
@@ -144,40 +186,11 @@ func (rm *resourceManager) getFunctionEventInvokeConfig(
144
186
Qualifier : ko .Spec .Name ,
145
187
},
146
188
)
147
-
148
189
rm .metrics .RecordAPICall ("GET" , "GetFunctionEventInvokeConfig" , err )
149
190
191
+ err = rm .setFunctionEventInvokeConfigFromResponse (ko , getFunctionEventInvokeConfigOutput , err )
150
192
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
- }
193
+ return err
181
194
}
182
195
183
196
return nil
@@ -191,14 +204,16 @@ func (rm *resourceManager) setResourceAdditionalFields(
191
204
exit := rlog .Trace ("rm.setResourceAdditionalFields" )
192
205
defer exit (err )
193
206
194
- eic_err := rm .getFunctionEventInvokeConfig (ctx , ko )
195
- if eic_err != nil {
196
- return eic_err
207
+ // To set Asynchronous Invocations for the function's alias
208
+ err = rm .setFunctionEventInvokeConfig (ctx , ko )
209
+ if err != nil {
210
+ return err
197
211
}
198
212
199
- pc_err := rm .getProvisionedConcurrencyConfig (ctx , ko )
200
- if pc_err != nil {
201
- return pc_err
213
+ // To set Provisioned Concurrency for the function's alias
214
+ err = rm .setProvisionedConcurrencyConfig (ctx , ko )
215
+ if err != nil {
216
+ return err
202
217
}
203
218
204
219
return nil
0 commit comments