forked from ansible-collections/community.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.
Cleanup lambda_alias (ansible-collections#396)
* Update lambda_alias to use AnsibleAWSModule.client * Update lambda_alias to use fail_json_aws * Replace custom snake/camel conversion * lambda_alias replace use of AWSConnection with passing a standard (wrapped) boto3 connection * Enable Retries * Fix idempotency when description isn't set. * Don't throw an exception when attempting to create a new alias in check mode * Add revision_id to return docs * Add integration tests * add changelog
- Loading branch information
1 parent
b01aa57
commit 7d59e69
Showing
8 changed files
with
735 additions
and
82 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
minor_changes: | ||
- lambda_alias - use common helper functions to create AWS connections (https://github.com/ansible-collections/community.aws/pull/396). | ||
- lambda_alias - use common helper functions to perform snake_case to CamelCase conversions (https://github.com/ansible-collections/community.aws/pull/396). | ||
- lambda_alias - add retries on common AWS failures (https://github.com/ansible-collections/community.aws/pull/396). |
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,2 @@ | ||
cloud/aws | ||
shippable/aws/group3 |
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,10 @@ | ||
--- | ||
# defaults file for lambda integration test | ||
lambda_function_name: '{{ resource_prefix }}' | ||
# IAM role names have to be less than 64 characters | ||
# The 8 digit identifier at the end of resource_prefix helps determine during | ||
# which test something was created and allows tests to be run in parallel | ||
# Shippable resource_prefixes are in the format shippable-123456-123, so in those cases | ||
# we need both sets of digits to keep the resource name unique | ||
unique_id: "{{ resource_prefix | regex_search('(\\d+-?)(\\d+)$') }}" | ||
lambda_role_name: 'ansible-test-{{ unique_id }}-lambda' |
48 changes: 48 additions & 0 deletions
48
tests/integration/targets/lambda_alias/files/mini_lambda.py
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() |
12 changes: 12 additions & 0 deletions
12
tests/integration/targets/lambda_alias/files/minimal_trust_policy.json
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,12 @@ | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": "lambda.amazonaws.com" | ||
}, | ||
"Action": "sts:AssumeRole" | ||
} | ||
] | ||
} |
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.