Skip to content

AWS Cross account access using table ARN with query #850

@mzientkowski

Description

@mzientkowski

Version: 3.10.0

Issue: Querying GSI with AWS Cross-Account Access in Dynamoid Uses Table Name Instead of Table ARN

Description

When querying a Global Secondary Index (GSI) in Dynamoid using AWS cross-account access, the library builds the query using the table name instead of the table ARN. This behavior causes issues since the correct ARN is required for cross-account access.

Example Code

class Offer
  include Dynamoid::Document

  table name: 'arn:aws:dynamodb:eu-west-1:123559793147:table/offers', key: :join_id, capacity_mode: :on_demand
  field :shop_id, :string
  field :sanitized_link, :string

  global_secondary_index name: :shop_id_sanitized_link,
                         hash_key: :shop_id, range_key: :sanitized_link, projected_attributes: :all
end

Steps to Reproduce

This works correctly since the table ARN is used under the hood.

Offer.find('join_id')

Attempt to query a GSI. The generated query uses the table name (offers) instead of the table ARN.

Offer.where(shop_id: 'shop_id', sanitized_url: 'sanitized_url').with_index(:shop_id_sanitized_link).first

Workaround

I implemented a monkey patch to resolve the issue temporarily:

class Dynamoid::AdapterPlugin::AwsSdkV3::Table
  def name
    schema[:table_arn]
  end
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions