GithubHelp home page GithubHelp logo

Comments (11)

devgripes avatar devgripes commented on May 27, 2024

it seems that it is related to dynamodb_tables that i misconfigured

from slam.

devgripes avatar devgripes commented on May 27, 2024

i have this database model using PynamoDB:

class UserEmailViewIndex(GlobalSecondaryIndex):
    class Meta:
        index_name = "email_view_index"
        read_capacity_units = 1
        write_capacity_units = 1
        projection = AllProjection()
    email = UnicodeAttribute(hash_key=True)

class User(Model):
    class Meta:
        table_name = os.environ.get('STAGE') + '.Users'
        region = boto3.Session().region_name
        host = 'http://localhost:8000' \
            if not os.environ.get('LAMBDA_TASK_ROOT') else None
    id = UnicodeAttribute(hash_key=True)
    first_name = UnicodeAttribute()
    last_name = UnicodeAttribute()
    email = UnicodeAttribute()
    password = UnicodeAttribute()
    address = MapAttribute()
    gender = UnicodeAttribute()
    mobile_number = UnicodeAttribute()
    birthday = UnicodeAttribute()
    accepted_terms = MapAttribute()
    email_view_index = UserEmailViewIndex()
    date_created = UTCDateTimeAttribute()
    date_updated = UTCDateTimeAttribute()
    last_login = UTCDateTimeAttribute()


class PurchaseUserViewIndex(GlobalSecondaryIndex):
    class Meta:
        index_name = "user_view_index"
        read_capacity_units = 1
        write_capacity_units = 1
        projection = AllProjection()
    user_id = UnicodeAttribute(hash_key=True)

class Purchase(Model):
    class Meta:
        table_name = os.environ.get('STAGE') +'.Purchases'
        region = boto3.Session().region_name
        host = 'http://localhost:8000' \
            if not os.environ.get('LAMBDA_TASK_ROOT') else None
    id = UnicodeAttribute(hash_key=True)
    user_id = UnicodeAttribute()
    amount = NumberAttribute()
    store_name = UnicodeAttribute()
    card_number = UnicodeAttribute()
    transaction_date = UnicodeAttribute()
    transaction_type = UnicodeAttribute()
    num_of_entries = NumberAttribute(default=0)
    campaign = MapAttribute()
    user_view_index = PurchaseUserViewIndex()
    date_created = UTCDateTimeAttribute()

and i have this in slam.yaml file:

dynamodb_tables:
  Purchases:
    attributes:
      id: "S"
      user_id: "S"
    key: "id"
    read_throughput: 1
    write_throughput: 1
    global_secondary_indexes:
      user_view_index:
        key: ["user_id"]
        project: "all"
        read_throughput: 1
        write_throughput: 1

  Users:
    attributes:
      id: "S"
      email: "S"
    key: "id"
    read_throughput: 1
    write_throughput: 1
    global_secondary_indexes:
      email_view_index:
        key: ["email"]
        project: "all"
        read_throughput: 1
        write_throughput: 1

and i have this error in AWS CloudFormation: Value of property GlobalSecondaryIndexes must be of type List

can you check if my config is correct? thanks

from slam.

miguelgrinberg avatar miguelgrinberg commented on May 27, 2024

@kuronaru This was a bug on my side. Please upgrade slam to latest release and retry.

from slam.

devgripes avatar devgripes commented on May 27, 2024

still no luck, i can't deploy my project because of the dynamo_table config in yaml

from slam.

devgripes avatar devgripes commented on May 27, 2024

i think there's something wrong with the projection.
i checked the template generated by slam template and the
"Projection": { "ProjectionType": "KEYS_ONLY" },

from slam.

miguelgrinberg avatar miguelgrinberg commented on May 27, 2024

I will run a complete example later when I have a bit of time. Do you know what is the error with the projection portion of the cloudformation template?

from slam.

devgripes avatar devgripes commented on May 27, 2024

i was able to deploy now after re-updating all the libraries in requirements.txt and i checked the template again and the ProjectionType is still set as KEYS_ONLY though i set it as all

i checked the logs by slam logs --tail

$ slam logs --tail
May 24 13:48:50 START RequestId: a7cf6548-4044-11e7-9534-17871a9c07ee Version: $LATEST
May 24 13:48:58 Failed to query items: An error occurred (AccessDeniedException) on request (PN8ILQLJ53EEIS2BQ9TNIBDKJNVV4KQNSO5AEMVJF66Q9ASUAAJG) on table (dev.Users) when calling the Query operation: : QueryError

is the template generating the policies right or i need to configure in the AWS console for this?

i also noticed that in API Gateway Resources at AWS Console it looks like the screenshot unlike using serverless:
screenshot_2017-05-24_14-01-47

is it normal to look like that?

please bear with me

from slam.

miguelgrinberg avatar miguelgrinberg commented on May 27, 2024

The project problem ended up being another bug. The documentation indicated you should use project, but in the code, I was using projection. I updated the code to match the documentation.

The API Gateway configuration is correct. I plan to eventually add support for authorization at the gateway level, but at this point, authorization can only be provided in the WSGI application.

from slam.

devgripes avatar devgripes commented on May 27, 2024

thanks for the response.
any idea what causes the QueryError like what in the slam logs?

from slam.

miguelgrinberg avatar miguelgrinberg commented on May 27, 2024

@kuronaru is that line in the log generated by your application? I'm not familiar with that log format. In any case, there is an AccessDeniedException. It would be useful if you let that exception bubble up, so that the log will show a complete error message and a stack trace.

from slam.

psaks avatar psaks commented on May 27, 2024

I had the same issue, and it turned out to be a issue with the yml file. In the following section you need to add;

iamRoleStatements:
    - Effect: Allow
      Action:
        - dynamodb:Query
        - dynamodb:Scan
        - dynamodb:GetItem
        - dynamodb:PutItem
        - dynamodb:UpdateItem
        - dynamodb:DeleteItem
        - dynamodb:DescribeTable
      Resource: 
        - "arn:aws:dynamodb:{YOUR-TABLE}/index/*"

In summary, you need to add specific permissions to the index to be able to query the GSI.

from slam.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.