SungardAS / lambda-formation

A small framework for building nodejs AWS Lambda projects that are compatible with AWS CloudFormation Custom Resources
Apache License 2.0
22 stars 4 forks source link

null values #6

Closed spa-87 closed 7 years ago

spa-87 commented 8 years ago

Hello again :), I've met a new issue with spotinst-lambda function. But I think it should be handled at current framework. The use-case: If I have already created Spotinst group with defined compute.launchSpecification.loadBalancerNames field, I can't unset that field (remove all load balancers for ElastiGroup). SpotInst API expects null value but CloudFormation templates don't allow null values. If I set {"Ref" : "AWS::NoValue"} value, the field just isn't sent to lambda function and eventually ElastiGroup parameter stays unchanged. If an empty array is provided, SpotInst API returns an error.

A solution could be some predefined string which is replaced with null value by current framework. For instance it can be "null" string.

kmcgrath commented 8 years ago

Thank you for submitting, I think we have 2 paths.

First, the method you mention where we use a string value or possibly our own null value object {"LambdaFormationRef": "null"}. The second option is a bit longer but ensures that we don't have conflicts with strings that are "null" and opens things up for other custom object types / pseudo references.

Another solution. The old configuration is sent along with the new configuration when UPDATE is called from CloudFormation. We could update spotinst-lambda to regonize keys that have been removed and set them to "null".

In true REST a PUT should always update an entire object and PATCH should be used to update parts of an object. It looks like Spotinst is treating PUT like PATCH. I would rather make the second change in spotinst-lambda instead of here because it is specific to the Spotinst API.

kmcgrath commented 8 years ago

I have some code in sungardas/spotinst-lambda#develop that should fix the issue. I still need to test this against the Spotinst API myself, but if you have time let me know if it works for you.

spa-87 commented 8 years ago

Yep, it works for me. I've tested all main actions like stack create/delete, value set/unset/modify. Looks like all is ok.

kmcgrath commented 8 years ago

Glad it works. I'll get the code promoted to master soon. Going to leave this open until I figure out if I want to implement a special null value here in lambda-formation.