Skip to content

Commit

Permalink
fix(delete): Remove Deletion Polling
Browse files Browse the repository at this point in the history
* There is an 8KB limit to `AWS::Events::Rule` resources that are
  created by the  `crhelper` library to implement a polling
  strategy for the custom resource.
* The polling strategies for `update` and `create` were previously
  removed in commit ad497ce, but
  the `poll_delete` function was not removed.
* For larger bot definitions (ie. > 8KB), the custom resource
  correctly creates and updates the bot resource, but it will
  fail on deletion with an error message of:

```
'targets.1.member.input' failed to satisfy constraint:

Member must have length less than or equal to 8192
```
* To resolve this issue, simply remove the `poll_delete` function
  and update the `delete_resource` function to wait for the bot
  and the bot alias to be fully deleted.

resolves: aws-samples#1
  • Loading branch information
Jesse Doyle committed Sep 24, 2021
1 parent 01395ac commit 3160103
Showing 1 changed file with 2 additions and 27 deletions.
29 changes: 2 additions & 27 deletions src/lambda_functions/lex_v2_cfn_cr/lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,33 +104,6 @@ def create_resource(event, _):

raise RuntimeError(f"Invalid resource type: {resource_type}")


@HELPER.poll_delete
def poll_delete(event, _):
"""Poll Delete"""
resource_type = event["ResourceType"]
helper_data = event["CrHelperData"]

if resource_type == "Custom::LexBot":
bot_id = helper_data.get("botId")
if bot_id:
LEX_CUSTOM_RESOURCE.wait_for_delete_bot(bot_id=bot_id)

return True

if resource_type == "Custom::LexBotVersion":
return True

if resource_type == "Custom::LexBotAlias":
bot_id = helper_data.get("botId")
bot_alias_id = helper_data.get("botAliasId")
if bot_id and bot_alias_id:
LEX_CUSTOM_RESOURCE.wait_for_delete_bot_alias(bot_id=bot_id, bot_alias_id=bot_alias_id)
return True

raise RuntimeError(f"Invalid resource type: {resource_type}")


@HELPER.delete
def delete_resource(event, _):
"""Delete Resource"""
Expand Down Expand Up @@ -163,6 +136,7 @@ def delete_resource(event, _):
if bot_id:
try:
LEX_CUSTOM_RESOURCE.delete_bot(bot_id=bot_id)
LEX_CUSTOM_RESOURCE.wait_for_delete_bot(bot_id=bot_id)
except CLIENT.exceptions.PreconditionFailedException:
LOGGER.info("Bot does not exist - bot_id: %s", bot_id)

Expand All @@ -183,6 +157,7 @@ def delete_resource(event, _):
if bot_alias_id and bot_id:
try:
LEX_CUSTOM_RESOURCE.delete_bot_alias(bot_id=bot_id, bot_alias_id=bot_alias_id)
LEX_CUSTOM_RESOURCE.wait_for_delete_bot_alias(bot_id=bot_id, bot_alias_id=bot_alias_id)
except CLIENT.exceptions.PreconditionFailedException:
LOGGER.info(
"Bot alias does not exist - bot_id: %s - bot_alias_id: %s",
Expand Down

0 comments on commit 3160103

Please sign in to comment.