Skip to content

Commit

Permalink
fix: Wait for Lambda function State = Active
Browse files Browse the repository at this point in the history
  • Loading branch information
falsedlah authored Sep 7, 2023
1 parent f2adea8 commit b427276
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion plugins/modules/lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@
import re

try:
from botocore.exceptions import ClientError, BotoCoreError
from botocore.exceptions import ClientError, BotoCoreError, WaiterError
except ImportError:
pass # protected by AnsibleAWSModule

Expand Down Expand Up @@ -327,6 +327,16 @@ def set_tag(client, module, tags, function):

return changed

def wait_for_lambda(client, module, name):
try:
client_active_waiter = client.get_waiter('function_active')
client_updated_waiter = client.get_waiter('function_updated')
client_active_waiter.wait(FunctionName=name)
client_updated_waiter.wait(FunctionName=name)
except WaiterError as e:
module.fail_json_aws(e, msg='Timeout while waiting on lambda to finish updating')
except (ClientError, BotoCoreError) as e:
module.fail_json_aws(e, msg='Failed while waiting on lambda to finish updating')

def main():
argument_spec = dict(
Expand Down Expand Up @@ -480,6 +490,8 @@ def main():

# Upload new configuration if configuration has changed
if len(func_kwargs) > 1:
if not check_mode:
wait_for_lambda(client, module, name)
try:
if not check_mode:
response = client.update_function_configuration(aws_retry=True, **func_kwargs)
Expand Down Expand Up @@ -524,6 +536,8 @@ def main():

# Upload new code if needed (e.g. code checksum has changed)
if len(code_kwargs) > 2:
if not check_mode:
wait_for_lambda(client, module, name)
try:
if not check_mode:
response = client.update_function_code(aws_retry=True, **code_kwargs)
Expand Down

0 comments on commit b427276

Please sign in to comment.