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

dynamodb_table - boto3 migration #726

Merged
merged 5 commits into from
Oct 11, 2021

Conversation

tremble
Copy link
Contributor

@tremble tremble commented Sep 20, 2021

SUMMARY

Existing boto3 migration (#65) seems to have been mangled by the migration to collections and has bit-rotted. Start from scratch and don't add new features.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

dynamodb_table

ADDITIONAL INFORMATION

@ansibullbot
Copy link

@ansibullbot ansibullbot added WIP Work in progress feature This issue/PR relates to a feature request integration tests/integration module module needs_triage plugins plugin (any type) tests tests labels Sep 20, 2021
@tremble tremble changed the title [WIP] dynamodb_table - boto3 migration dynamodb_table - boto3 migration Sep 22, 2021
@tremble
Copy link
Contributor Author

tremble commented Sep 22, 2021

@marknet15 if you have time it'd be appreciated if you could review/test this change. It looks like you've used the existing module?

@tremble tremble removed the WIP Work in progress label Sep 22, 2021
@marknet15
Copy link
Contributor

marknet15 commented Sep 22, 2021

For general provisioned tables it seems fine 👍🏻 I was able to create provisioned tables with and without indexes etc without an issue:

Task result:
changed: [localhost] => (item={'name': 'demoapp-example-indexes', 'hash_key_name': 'SomeId', 'hash_key_type': 'NUMBER', 'read_capacity': 1, 'write_capacity': 1, 'indexes': [{'name': 'TestId-Index', 'type': 'global_all', 'hash_key_name': 'TestId', 'hash_key_type': 'NUMBER'}]}) => {
    "ansible_loop_var": "table",
    "changed": true,
    "hash_key_name": "SomeId",
    "hash_key_type": "NUMBER",
    "indexes": [
        {
            "hash_key_name": "TestId",
            "hash_key_type": "NUMBER",
            "includes": [],
            "name": "TestId-Index",
            "range_key_name": null,
            "range_key_type": null,
            "read_capacity": 1,
            "type": "global_ALL",
            "write_capacity": 1
        }
    ],
    "invocation": {
        "module_args": {
            "aws_access_key": null,
            "aws_ca_bundle": null,
            "aws_config": null,
            "aws_secret_key": null,
            "debug_botocore_endpoint_logs": false,
            "ec2_url": null,
            "hash_key_name": "SomeId",
            "hash_key_type": "NUMBER",
            "indexes": [
                {
                    "hash_key_name": "TestId",
                    "hash_key_type": "NUMBER",
                    "includes": null,
                    "name": "TestId-Index",
                    "range_key_name": null,
                    "range_key_type": null,
                    "read_capacity": null,
                    "type": "ALL",
                    "write_capacity": null
                }
            ],
            "name": "demoapp-example-indexes",
            "profile": null,
            "purge_tags": true,
            "range_key_name": null,
            "range_key_type": null,
            "read_capacity": 1,
            "region": "eu-west-1",
            "security_token": null,
            "state": "present",
            "tags": {
                "Name": "demoapp",
                "smart_pipeline": "true"
            },
            "validate_certs": true,
            "wait": true,
            "wait_for_active_timeout": 60,
            "wait_timeout": 60,
            "write_capacity": 1
        }
    },
    "range_key_name": null,
    "range_key_type": null,
    "read_capacity": 1,
    "region": "eu-west-1",
    "table": {
        "hash_key_name": "SomeId",
        "hash_key_type": "NUMBER",
        "indexes": [
            {
                "hash_key_name": "TestId",
                "hash_key_type": "NUMBER",
                "name": "TestId-Index",
                "type": "global_all"
            }
        ],
        "name": "demoapp-example-indexes",
        "read_capacity": 1,
        "write_capacity": 1
    },
    "table_name": "demoapp-example-indexes",
    "table_status": "ACTIVE",
    "tags": {
        "Name": "demoapp",
        "smart_pipeline": "true"
    },
    "write_capacity": 1
}

However on editing the read / write capacity on an index I do get an error

"msg": "Failed to update table: Parameter validation failed:\nMissing required parameter in GlobalSecondaryIndexUpdates[0].Update.ProvisionedThroughput: \"WriteCapacityUnits\"",

Example:

- name: Create DynamoDB tables
  community.aws.dynamodb_table:
    name: "demoapp-example-indexes"
    read_capacity: 1
    write_capacity: 1
    hash_key_name: "SomeId"
    hash_key_type: "NUMBER"
    indexes:
      - name: TestId-Index
        type: global_all
        hash_key_name: TestId
        hash_key_type: NUMBER
        read_capacity: 5
        write_capacity: 1
    region: "eu-west-1"
    state: present
Task result:
The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_community.aws.dynamodb_table_payload_z5__r9u5/ansible_community.aws.dynamodb_table_payload.zip/ansible_collections/community/aws/plugins/modules/dynamodb_table.py", line 739, in _update_table
  File "/tmp/ansible_community.aws.dynamodb_table_payload_z5__r9u5/ansible_community.aws.dynamodb_table_payload.zip/ansible_collections/amazon/aws/plugins/module_utils/core.py", line 334, in deciding_wrapper
    return retrying_wrapper(*args, **kwargs)
  File "/tmp/ansible_community.aws.dynamodb_table_payload_z5__r9u5/ansible_community.aws.dynamodb_table_payload.zip/ansible_collections/amazon/aws/plugins/module_utils/cloud.py", line 125, in _retry_wrapper
    base_class=cls.base_class,
  File "/tmp/ansible_community.aws.dynamodb_table_payload_z5__r9u5/ansible_community.aws.dynamodb_table_payload.zip/ansible_collections/amazon/aws/plugins/module_utils/cloud.py", line 68, in _retry_func
    return func()
  File "/usr/local/lib/python3.7/site-packages/botocore/client.py", line 386, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/usr/local/lib/python3.7/site-packages/botocore/client.py", line 678, in _make_api_call
    api_params, operation_model, context=request_context)
  File "/usr/local/lib/python3.7/site-packages/botocore/client.py", line 726, in _convert_to_request_dict
    api_params, operation_model)
  File "/usr/local/lib/python3.7/site-packages/botocore/validate.py", line 337, in serialize_to_request
    raise ParamValidationError(report=report.generate_report())
botocore.exceptions.ParamValidationError: Parameter validation failed:
Missing required parameter in GlobalSecondaryIndexUpdates[0].Update.ProvisionedThroughput: "WriteCapacityUnits"
fatal: [localhost]: FAILED! => {
    "boto3_version": "1.18.0",
    "botocore_version": "1.21.45",
    "changed": false,
    "invocation": {
        "module_args": {
            "aws_access_key": null,
            "aws_ca_bundle": null,
            "aws_config": null,
            "aws_secret_key": null,
            "debug_botocore_endpoint_logs": false,
            "ec2_url": null,
            "hash_key_name": "SomeId",
            "hash_key_type": "NUMBER",
            "indexes": [
                {
                    "hash_key_name": "TestId",
                    "hash_key_type": "NUMBER",
                    "includes": null,
                    "name": "TestId-Index",
                    "range_key_name": null,
                    "range_key_type": null,
                    "read_capacity": 5,
                    "type": "global_all",
                    "write_capacity": 1
                }
            ],
            "name": "demoapp-example-indexes",
            "profile": null,
            "purge_tags": true,
            "range_key_name": null,
            "range_key_type": null,
            "read_capacity": 1,
            "region": "eu-west-1",
            "security_token": null,
            "state": "present",
            "tags": null,
            "validate_certs": true,
            "wait": true,
            "wait_timeout": 120,
            "write_capacity": 1
        }
    },
    "msg": "Failed to update table: Parameter validation failed:\nMissing required parameter in GlobalSecondaryIndexUpdates[0].Update.ProvisionedThroughput: \"WriteCapacityUnits\""
}

@alinabuzachis
Copy link
Contributor

recheck

@alinabuzachis
Copy link
Contributor

@tremble

TASK [dynamodb_table : Check results - Tag table] ******************************
task path: /home/zuul/.ansible/collections/ansible_collections/community/aws/tests/integration/targets/dynamodb_table/tasks/main.yml:139
fatal: [testhost]: FAILED! => {
    "assertion": "tag_table.tags == tags_default",
    "changed": false,
    "evaluated_to": false,
    "msg": "Assertion failed"
}

@tremble
Copy link
Contributor Author

tremble commented Sep 22, 2021

@alinabuzachis That shows up when the module's blocked from accessing tags.

I've run the code locally against a copy of the perms and it's working. Maybe @jillr could double-check that the permissions from mattclay/aws-terminator#163 are live...

@tremble
Copy link
Contributor Author

tremble commented Sep 23, 2021

@marknet15 Many thanks for catching that bug, I've added a fix and some extra tests.

@marknet15
Copy link
Contributor

@tremble I had a look through because I was curious and was working on the billing_mode and it's definitely permissions related:

TASK [dynamodb_table : Create table] *******************************************
task path: /home/zuul/.ansible/collections/ansible_collections/community/aws/tests/integration/targets/dynamodb_table/tasks/main.yml:33
Using module file /home/zuul/.ansible/collections/ansible_collections/community/aws/plugins/modules/dynamodb_table.py
Pipelining is enabled.
<testhost> ESTABLISH LOCAL CONNECTION FOR USER: zuul
<testhost> EXEC /bin/sh -c 'ANSIBLE_DEBUG_BOTOCORE_LOGS=True /home/zuul/venv/bin/python && sleep 0'

[WARNING]: Permission denied when listing tags
changed: [testhost] => {
    "changed": true,

locally yeah I see all tags etc, I created mattclay/aws-terminator#171 with a slight adjustment, maybe that would help

@tremble tremble added the gate label Oct 11, 2021
Copy link
Contributor

@ansible-zuul ansible-zuul bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@ansible-zuul ansible-zuul bot merged commit e3a50c4 into ansible-collections:main Oct 11, 2021
@nick-zh
Copy link

nick-zh commented Oct 12, 2021

Many thanks for this 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community_review feature This issue/PR relates to a feature request has_issue integration tests/integration module module needs_triage plugins plugin (any type) tests tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants