Below is the command to generate models from database directly in quick fashion.

$ pip install sqlacodegen

$ pip install pymysql

Create your db schema.

now issue the following command

$ sqlacodegen mysql+pymysql://Nich:Bossdk#@localhost/dev

the output will be like given below

class User(Base):
__tablename__ = ‘user’

user_id = Column(Integer, primary_key=True)
first_name = Column(String(255), nullable=False)
last_name = Column(String(255))
email_id = Column(String(255), unique=True)
phone_no = Column(BigInteger)
country = Column(String(50))
_pass = Column(‘pass’, String(255))



Run the following commands

npm install -g serverless

serverless config credentials --provider aws --key XXXXXXXXXEXAMPLE --secret XXXXXXXXX/XXXXXXX/XXXXXXXXX

Also make sure the IAM user for which we would be using aws key and secret should have following policies attached

serverless create — template aws-nodejs — path hello-world-medium

cd hello-world-medium

serverless deploy -v



I created the lambda function to generate access token and id token as mentioned in my previous blogs.The access token we decoded will show something like.

“sub”: “5ccc31a1–4934–455f-8d83–1ec4b49b1df2”,
“cognito:groups”: [
“event_id”: “e4308419–92da-49e5–961a-b3df624e3c40”,
“token_use”: “access”,
“scope”: “aws.cognito.signin.user.admin”,
“auth_time”: 1610342817,
“iss”: “",
“exp”: 1610346417,
“iat”: 1610342817,
“jti”: “83abd9c1–1a08–41af-bc37-d6d64a68d7e6”,
“client_id”: “2o6lf8lfpb70l6f99bg7anai6m”,
“username”: “8ccc31a1–4934–455f-8d83–1ec4b49b1df2”

The main troublemaker is the scope which by default assigns admin to every user which by design is useless and flaw from AWS.

Hence if one want’s RBAC then i would recommend to go by IAM based access using federated identities pool setting creating custom role and assign it user groups in Cognito user pool.