Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression: cloudwatchevent_rule doesn't properly support JSON input_templates #1842

Closed
1 task done
alalonde opened this issue Nov 2, 2023 · 0 comments · Fixed by #1883
Closed
1 task done

Regression: cloudwatchevent_rule doesn't properly support JSON input_templates #1842

alalonde opened this issue Nov 2, 2023 · 0 comments · Fixed by #1883
Labels
jira needs_verified Some one might want to take a look at this and reproduce it to confirm p2

Comments

@alalonde
Copy link

alalonde commented Nov 2, 2023

Summary

I reported this same bug over in the community.aws collection last year. It seems to have returned in this code.

Please see the previous issue report for a detailed reproduction example.

Issue Type

Bug Report

Component Name

cloudwatchevent_rule

Ansible Version

$ ansible --version

Collection Versions

$ ansible-galaxy collection list

AWS SDK versions

$ pip show boto boto3 botocore

Configuration

$ ansible-config dump --only-changed

OS / Environment

No response

Steps to Reproduce

Here is a working example using the AWS CLI:

eventbridge_target.json
{
   "Rule": "myRule",
   "Targets": [{
      ...
      "InputTransformer": {
         "InputPathsMap": {
            "s3Key": "$.detail.object.key"
         },
         "InputTemplate": "{\"containerOverrides\": [{\"name\": \"thrivSportsJob-stage_jobmg10\", \"environment\": [{\"name\": \"S3_KEY\",\"value\": <s3Key>}]}]}"
      }
   }]
}

Which can be executed with a aws events put-targets --cli-input-json file://eventbridge_target.json

However, when parsing the target configuration, the input is wrapped in a string:

                target_request['InputTransformer']['InputTemplate'] = '"{0}"'.format(
                    target['input_template']
                )

AWS will not route an event with an invalid transformer template. So the input for a JSON template must begin with a {, not a ". My solution was to remove the string wrapping, AND prepend the template with a space, as recommended here. This results in:

      -  name: Define trigger input template
         set_fact:
            trigger_input_template: |
               {
                  "containerOverrides": [{
                     "name": "{{container_name}}",
                     "environment": [{
                        "name": "S3_KEY",
                        "value": <s3Key>
                     }]
                  }]
               }
      -  name: Create rule in EventBridge
         community.aws.cloudwatchevent_rule:
            ...
            targets:
               -  id: "myJob-{{env}}"
                  ...
                  input_paths_map:
                     s3Key: "$.detail.object.key"
                  input_template: " {{trigger_input_template}}"
                  ...

Expected Results

I expected the input template to be wrapped by { ... } but was instead "{ ... }"

image

Actual Results

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@jillr jillr added needs_verified Some one might want to take a look at this and reproduce it to confirm jira p2 and removed needs_triage labels Nov 14, 2023
softwarefactory-project-zuul bot pushed a commit that referenced this issue Dec 18, 2023
cloudwatchevent_rule: Fix json input handling for input_template

SUMMARY

Fixes #1842
This PR


Moves _snakify() out of class CloudWatchEventRule https://github.com/ansible-collections/amazon.aws/pull/1883/files#diff-3a2f223edc4e34ea28b9859827a830844d92a8cd97f1300a2d16b1703a083bc8R213-R215


Fixes conditional in function _targets_to_put() to avoid wrong results due to _snakify() https://github.com/ansible-collections/amazon.aws/pull/1883/files#diff-3a2f223edc4e34ea28b9859827a830844d92a8cd97f1300a2d16b1703a083bc8R461-R463


Updates code to add quotes " to input_template only when the given input is not JSON to avoid quotes being added to provided JSON input https://github.com/ansible-collections/amazon.aws/pull/1883/files#diff-3a2f223edc4e34ea28b9859827a830844d92a8cd97f1300a2d16b1703a083bc8R452-R458



ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME

cloudwatchevent_rule
ADDITIONAL INFORMATION

Reviewed-by: Bikouo Aubin
Reviewed-by: Helen Bailey <[email protected]>
Reviewed-by: Alina Buzachis
Reviewed-by: Mandar Kulkarni <[email protected]>
patchback bot pushed a commit that referenced this issue Feb 8, 2024
cloudwatchevent_rule: Fix json input handling for input_template

SUMMARY

Fixes #1842
This PR

Moves _snakify() out of class CloudWatchEventRule https://github.com/ansible-collections/amazon.aws/pull/1883/files#diff-3a2f223edc4e34ea28b9859827a830844d92a8cd97f1300a2d16b1703a083bc8R213-R215

Fixes conditional in function _targets_to_put() to avoid wrong results due to _snakify() https://github.com/ansible-collections/amazon.aws/pull/1883/files#diff-3a2f223edc4e34ea28b9859827a830844d92a8cd97f1300a2d16b1703a083bc8R461-R463

Updates code to add quotes " to input_template only when the given input is not JSON to avoid quotes being added to provided JSON input https://github.com/ansible-collections/amazon.aws/pull/1883/files#diff-3a2f223edc4e34ea28b9859827a830844d92a8cd97f1300a2d16b1703a083bc8R452-R458

ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME

cloudwatchevent_rule
ADDITIONAL INFORMATION

Reviewed-by: Bikouo Aubin
Reviewed-by: Helen Bailey <[email protected]>
Reviewed-by: Alina Buzachis
Reviewed-by: Mandar Kulkarni <[email protected]>
(cherry picked from commit 3b67513)
patchback bot pushed a commit that referenced this issue Feb 8, 2024
cloudwatchevent_rule: Fix json input handling for input_template

SUMMARY

Fixes #1842
This PR

Moves _snakify() out of class CloudWatchEventRule https://github.com/ansible-collections/amazon.aws/pull/1883/files#diff-3a2f223edc4e34ea28b9859827a830844d92a8cd97f1300a2d16b1703a083bc8R213-R215

Fixes conditional in function _targets_to_put() to avoid wrong results due to _snakify() https://github.com/ansible-collections/amazon.aws/pull/1883/files#diff-3a2f223edc4e34ea28b9859827a830844d92a8cd97f1300a2d16b1703a083bc8R461-R463

Updates code to add quotes " to input_template only when the given input is not JSON to avoid quotes being added to provided JSON input https://github.com/ansible-collections/amazon.aws/pull/1883/files#diff-3a2f223edc4e34ea28b9859827a830844d92a8cd97f1300a2d16b1703a083bc8R452-R458

ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME

cloudwatchevent_rule
ADDITIONAL INFORMATION

Reviewed-by: Bikouo Aubin
Reviewed-by: Helen Bailey <[email protected]>
Reviewed-by: Alina Buzachis
Reviewed-by: Mandar Kulkarni <[email protected]>
(cherry picked from commit 3b67513)
softwarefactory-project-zuul bot pushed a commit that referenced this issue Feb 13, 2024
…) (#1968)

[PR #1883/3b67513e backport][stable-7] cloudwatchevent_rule: Fix json input handling for input_template

This is a backport of PR #1883 as merged into main (3b67513).
SUMMARY

Fixes #1842
This PR


Moves _snakify() out of class CloudWatchEventRule https://github.com/ansible-collections/amazon.aws/pull/1883/files#diff-3a2f223edc4e34ea28b9859827a830844d92a8cd97f1300a2d16b1703a083bc8R213-R215


Fixes conditional in function _targets_to_put() to avoid wrong results due to _snakify() https://github.com/ansible-collections/amazon.aws/pull/1883/files#diff-3a2f223edc4e34ea28b9859827a830844d92a8cd97f1300a2d16b1703a083bc8R461-R463


Updates code to add quotes " to input_template only when the given input is not JSON to avoid quotes being added to provided JSON input https://github.com/ansible-collections/amazon.aws/pull/1883/files#diff-3a2f223edc4e34ea28b9859827a830844d92a8cd97f1300a2d16b1703a083bc8R452-R458



ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME

cloudwatchevent_rule
ADDITIONAL INFORMATION

Reviewed-by: Alina Buzachis
softwarefactory-project-zuul bot pushed a commit that referenced this issue Feb 13, 2024
…) (#1969)

[PR #1883/3b67513e backport][stable-6] cloudwatchevent_rule: Fix json input handling for input_template

This is a backport of PR #1883 as merged into main (3b67513).
SUMMARY

Fixes #1842
This PR


Moves _snakify() out of class CloudWatchEventRule https://github.com/ansible-collections/amazon.aws/pull/1883/files#diff-3a2f223edc4e34ea28b9859827a830844d92a8cd97f1300a2d16b1703a083bc8R213-R215


Fixes conditional in function _targets_to_put() to avoid wrong results due to _snakify() https://github.com/ansible-collections/amazon.aws/pull/1883/files#diff-3a2f223edc4e34ea28b9859827a830844d92a8cd97f1300a2d16b1703a083bc8R461-R463


Updates code to add quotes " to input_template only when the given input is not JSON to avoid quotes being added to provided JSON input https://github.com/ansible-collections/amazon.aws/pull/1883/files#diff-3a2f223edc4e34ea28b9859827a830844d92a8cd97f1300a2d16b1703a083bc8R452-R458



ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME

cloudwatchevent_rule
ADDITIONAL INFORMATION

Reviewed-by: Alina Buzachis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
jira needs_verified Some one might want to take a look at this and reproduce it to confirm p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants