Skip to content

Commit ab5d417

Browse files
committed
Fixed an issue where NullReferenceException was thrown while invoking AmazonCloudFormationClient.UpdateStackAsync().
1 parent c9c869c commit ab5d417

File tree

3 files changed

+103
-5
lines changed

3 files changed

+103
-5
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"services": [
3+
{
4+
"serviceName": "CloudFormation",
5+
"type": "patch",
6+
"changeLogMessages": [ "Fixed an issue where NullReferenceException was thrown while invoking AmazonCloudFormationClient.UpdateStackAsync()." ]
7+
}
8+
]
9+
}

sdk/src/Services/CloudFormation/Custom/Internal/ProcessRequestHandler.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,22 @@ protected virtual void PreInvoke(IExecutionContext executionContext)
6868
if (updateStackRequest != null)
6969
{
7070
var arns = updateStackRequest.NotificationARNs;
71-
bool arnsAutoConstructed = arns is AutoConstructedList<string>;
7271

73-
// if there are no NotificationARNs and the list was created by user (type is NOT AutoConstructed)
74-
// only then pass empty param
75-
if (arns.Count == 0 && !arnsAutoConstructed)
72+
if (arns != null)
7673
{
77-
request.Parameters.Add("NotificationARNs", "");
74+
// if there are no NotificationARNs and the list was created by user (type is NOT AutoConstructed)
75+
// only then pass empty param
76+
if (arns.Count == 0 && !(arns is AutoConstructedList<string>))
77+
{
78+
if (request.Parameters.ContainsKey("NotificationARNs"))
79+
{
80+
request.Parameters["NotificationARNs"] = string.Empty;
81+
}
82+
else
83+
{
84+
request.Parameters.Add("NotificationARNs", string.Empty);
85+
}
86+
}
7887
}
7988
}
8089
}

sdk/test/Services/CloudFormation/IntegrationTests/CloudFormation.cs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,86 @@ public void TestCreateStack()
218218
}
219219
}
220220

221+
[TestMethod]
222+
[TestCategory("CloudFormation")]
223+
public void TestUpdateStack()
224+
{
225+
string stackName = "test-stack-" + DateTime.UtcNow.Ticks;
226+
try
227+
{
228+
CreateStackRequest createRequest = new CreateStackRequest
229+
{
230+
StackName = stackName,
231+
TemplateBody = TEMPLATE_TEXT,
232+
Parameters = new List<Parameter>
233+
{
234+
new Parameter
235+
{
236+
ParameterKey = "TopicName",
237+
ParameterValue = "MyTopic" + DateTime.UtcNow.Ticks
238+
},
239+
new Parameter
240+
{
241+
ParameterKey = "QueueName",
242+
ParameterValue = "MyQueue" + DateTime.UtcNow.Ticks
243+
}
244+
}
245+
};
246+
247+
Client.CreateStack(createRequest);
248+
WaitTillStackNotInProcess(stackName);
249+
250+
UpdateStackRequest updateStackRequest = new UpdateStackRequest
251+
{
252+
StackName = stackName,
253+
TemplateBody = TEMPLATE_TEXT,
254+
Parameters = new List<Parameter>
255+
{
256+
new Parameter
257+
{
258+
ParameterKey = "TopicName",
259+
ParameterValue = "MyTopic" + DateTime.UtcNow.Ticks
260+
},
261+
new Parameter
262+
{
263+
ParameterKey = "QueueName",
264+
ParameterValue = "MyQueue" + DateTime.UtcNow.Ticks
265+
}
266+
}
267+
};
268+
269+
Client.UpdateStack(updateStackRequest);
270+
WaitTillStackNotInProcess(stackName);
271+
272+
updateStackRequest = new UpdateStackRequest
273+
{
274+
StackName = stackName,
275+
TemplateBody = TEMPLATE_TEXT,
276+
Parameters = new List<Parameter>
277+
{
278+
new Parameter
279+
{
280+
ParameterKey = "TopicName",
281+
ParameterValue = "MyTopic" + DateTime.UtcNow.Ticks
282+
},
283+
new Parameter
284+
{
285+
ParameterKey = "QueueName",
286+
ParameterValue = "MyQueue" + DateTime.UtcNow.Ticks
287+
}
288+
},
289+
NotificationARNs = new List<string>()
290+
};
291+
Client.UpdateStack(updateStackRequest);
292+
WaitTillStackNotInProcess(stackName);
293+
}
294+
finally
295+
{
296+
WaitTillStackNotInProcess(stackName);
297+
Client.DeleteStack(new DeleteStackRequest() { StackName = stackName });
298+
}
299+
}
300+
221301
static void WaitTillStackNotInProcess(string stackname)
222302
{
223303
DescribeStacksResponse response = null;

0 commit comments

Comments
 (0)