skip to Main Content

We have a MySql DB on AWS, and we are using Lambdas with CDK, built on Typescript.
We have many CRUD operations across various lambdas.
However, on one lambda, the update of a row on a Table is not working.
An integration test run on a local DB works fine, and the affected rows give expected results. But running on AWS for this use case, calling the exact method that was integration tested, simply has no effect. The operation returns 0 affected rows, and no ValidationError is thrown, despite the transaction having changed data fields. We have tried using both the sequelize update method, and the save method. One interesting aspect is that the update query works fine if we update an old field. For the brand new fields, the update does not work. The DB migrations for new fields were run identically for the local integration test DB and the AWS DB.
The team cannot work out the issue.
Any ideas?

Code example:

async function updateMyValuesInUserDb(myParam: string, user: UserDbModel): Promise<void> {
    try {
        const value1 = getValue1(myParam)
        const value2 = getValue2(myParam)
      
        user.myNewField1 = value1
        user.myNewField2 = value2
        await user.save()
}

Model:

@Table({
    tableName: 'User',
    freezeTableName: true
})
export class UserDbModel extends Model {
    @PrimaryKey
    @AutoIncrement
    @Unique
    @Column
    id!: number

    @Column
    username: string

    @Column
    firstName: string

    @Column
    lastName: string

    @IsEmail
    @Unique
    @Column
    email: string

    @Default(false)
    @Column
    myNewField1: boolean

    @AllowNull(true)
    @Default(null)
    @Column
    myNewField2: number

    @UpdatedAt
    @Column
    updatedAt: Date

}

2

Answers


  1. Chosen as BEST ANSWER

    The issue is that although the integration tests were using the latest User model, the deployed code onto AWS was using an outdated User model, due to a package being out of date in package.json. We use symlinks to connect packages, and the deploy from local should factor in the symlink. Unfortunately, the symlink only worked for the integration test. We could have discovered this earlier if we had opened up the deployed/built code, and searched for the new fields.


  2. I suspect that the getValue1() and the getValue2() functions are asynchronous calls and need to have the await keyword applied so that the runtime will wait for the Promises to resolve.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search