I'm trying to use a condition to put a intem on DynamoDB, but doesn't work.
I have a table of users and a attribute id as primary key and attibute name must be unique.
conditions := aws.String("NOT contains(email, :e_email)")
attributes := map[string]*dynamodb.AttributeValue{
":e_mail": &dynamodb.AttributeValue{
S: &user.Email,
},
}
input := &dynamodb.PutItemInput{
Item: item,
TableName: dynamoTable,
ConditionExpression: conditions,
ExpressionAttributeValues: attributes,
}
_, err = dynamo.PutItemWithContext(ctx1, input)
if err != nil {
if erro, ok := err.(awserr.Error); ok {
if erro.Code() == dynamodb.ErrCodeConditionalCheckFailedException {
log.Println("User already exists")
body, _ := json.Marshal(models.ErrUsuarioJaExiste)
resp.StatusCode = models.ErrUsuarioJaExiste.CodigoHTTP
resp.Body = string(body)
return resp
}
}
log.Println(err)
resp.StatusCode = models.ErrInterno.CodigoHTTP
body, _ := json.Marshal(models.ErrInterno)
resp.Body = string(body)
return resp
}
But I still can add items with the same email