I would like to combine two JSON objects from the two commands below, in order to replace existing S3 notifications with a newer one, using put-bucket-notification-configuration. The combine filter I'm using is currently giving me an error saying that it expects dictionaries.
---
- name: Get existing S3 notifications
command: >
aws s3api get-bucket-notification-configuration
--bucket "{{ s3_notification.bucket }}"
--region "{{ aws_region }}"
register: existing_s3_notifications
environment:
AWS_ACCESS_KEY_ID: "{{ assumed_role.sts_creds.access_key }}"
AWS_SECRET_ACCESS_KEY: "{{ assumed_role.sts_creds.secret_key }}"
AWS_SECURITY_TOKEN: "{{ assumed_role.sts_creds.session_token }}"
- name: Combine existing S3 notifications with new notifications
command: >
aws s3api put-bucket-notification-configuration
--bucket "{{ s3_notification.bucket }}"
--notification-configuration '{{ s3_notification.configuration | to_json | combine(existing_s3_notifications) }}'
--region "{{ aws_region }}"
environment:
AWS_ACCESS_KEY_ID: "{{ assumed_role.sts_creds.access_key }}"
AWS_SECRET_ACCESS_KEY: "{{ assumed_role.sts_creds.secret_key }}"
AWS_SECURITY_TOKEN: "{{ assumed_role.sts_creds.session_token }}"
The JSON objects look like this:
{
"LambdaFunctionConfigurations": [
{
"Id": "dev-datamining-wwang-new_product_list",
"LambdaFunctionArn": "arn:aws:lambda:us-west-2:434815900134:function:dev-datamining-wwang-lambda-update_product_corpus",
"Events": [
"s3:ObjectCreated:*"
],
"Filter": {
"Key": {
"FilterRules": [
{
"Name": "Prefix",
"Value": "wwang/product_list/"
}
]
}
}
}
]
}
With another one like this:
{
"LambdaFunctionConfigurations": [
{
"Id": "dev-datamining-alee-new_product_list",
"LambdaFunctionArn": "arn:aws:lambda:us-west-2:434815900135:function:dev-datamining-alee-lambda-update_product_corpus",
"Events": [
"s3:ObjectCreated:*"
],
"Filter": {
"Key": {
"FilterRules": [
{
"Name": "Prefix",
"Value": "alee/product_list/"
}
]
}
}
}
],
"TopicConfigurations": [
<other stuff>
]
}
I'd like the result to be:
{
"LambdaFunctionConfigurations": [
{
"Id": "dev-datamining-wwang-new_product_list",
"LambdaFunctionArn": "arn:aws:lambda:us-west-2:434815900134:function:dev-datamining-wwang-lambda-update_product_corpus",
"Events": [
"s3:ObjectCreated:*"
],
"Filter": {
"Key": {
"FilterRules": [
{
"Name": "Prefix",
"Value": "wwang/product_list/"
}
]
}
}
},
{
"Id": "dev-datamining-alee-new_product_list",
"LambdaFunctionArn": "arn:aws:lambda:us-west-2:434815900135:function:dev-datamining-alee-lambda-update_product_corpus",
"Events": [
"s3:ObjectCreated:*"
],
"Filter": {
"Key": {
"FilterRules": [
{
"Name": "Prefix",
"Value": "alee/product_list/"
}
]
}
}
}
],
"TopicConfigurations": [
<other stuff>
]
}
How would I combine these two objects so that the arrays inside the objects are merged together?