forked from ansible-collections/amazon.aws
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lambda AnsibleAWSModule cleanup (also enable retries) (#5)
* Bomb out early if someone tries to set tags without the necessary botocore version * Simplify some error handling by using fail_json_aws * Use BotoCoreError rather than the sub-errors We still bomb out, but fail_json_aws is more graceful and user friendly than an uncaught Boto3 error. * use is_boto3_error_code to limit what we catch rather than catching and re-raising. * Cleanup get_account_info - use module.client to avoid the mass of extra args - use is_boto3_error_code('AccessDenied') to be a little cleaner - fix text search (re.search(, mystring) rather than mystring.search()) * Use module.client helpers * Delete dead code path - we test for having *both* vpc_subnet_ids and vpc_security_group_ids when we parse the arguments * Enable basic AWS Retries * Tweak integration test to allow for common 'missing region' error message * Rename lambda tests from 'aws_lambda' to 'lambda' (matching the module name) * Use omit rather than 'null' in the tests - ansible/ansible#69190 * Ignore duplicate-except warnings (it's caused by the way is_boto3_error works) * change expected error messages now we're using an AnsibleAWSModule feature This commit was initially merged in https://github.com/ansible-collections/community.aws See: ansible-collections/community.aws@d4e4d3e
- Loading branch information
1 parent
1c883b2
commit 8e6249f
Showing
6 changed files
with
514 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
cloud/aws | ||
shippable/aws/group2 | ||
execute_lambda | ||
lambda_info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
# defaults file for aws_lambda test | ||
lambda_function_name: '{{resource_prefix}}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) | ||
|
||
from __future__ import (absolute_import, division, print_function) | ||
__metaclass__ = type | ||
|
||
import json | ||
import os | ||
|
||
|
||
def handler(event, context): | ||
""" | ||
The handler function is the function which gets called each time | ||
the lambda is run. | ||
""" | ||
# printing goes to the cloudwatch log allowing us to simply debug the lambda if we can find | ||
# the log entry. | ||
print("got event:\n" + json.dumps(event)) | ||
|
||
# if the name parameter isn't present this can throw an exception | ||
# which will result in an amazon chosen failure from the lambda | ||
# which can be completely fine. | ||
|
||
name = event["name"] | ||
|
||
# we can use environment variables as part of the configuration of the lambda | ||
# which can change the behaviour of the lambda without needing a new upload | ||
|
||
extra = os.environ.get("EXTRA_MESSAGE") | ||
if extra is not None and len(extra) > 0: | ||
greeting = "hello {0}. {1}".format(name, extra) | ||
else: | ||
greeting = "hello " + name | ||
|
||
return {"message": greeting} | ||
|
||
|
||
def main(): | ||
""" | ||
This main function will normally never be called during normal | ||
lambda use. It is here for testing the lambda program only. | ||
""" | ||
event = {"name": "james"} | ||
context = None | ||
print(handler(event, context)) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
dependencies: | ||
- prepare_tests | ||
- setup_ec2 |
Oops, something went wrong.