Hey All. I spent some time setting up a Go SST res...
# help
b
Hey All. I spent some time setting up a Go SST rest Api yesterday which all works great but when i added Dynamo DB to it i cant seem to get it working locally. I’m using Dynamo’s putItemWithContext API which doesn’t throw any errors but also doesnt seem to write to the table and instead returns an empty struct. Any ideas?
f
Hi @Bobby Ross, can you share a snippet of your code?
b
Hey sure, il paste in a snippet as soon as I’m back at my desk
in create.go
Copy code
func (lambdaContext *lambdaContext) handler(ctx context.Context, req events.APIGatewayProxyRequest) (accounts.Response, error) {
	reqAccountBody, err := parseAccountBody(req.Body)
	_, err = lambdaContext.AccountService.CreateAccount(ctx, &reqAccountBody)

	if err != nil {
		return accounts.Fail(err, http.StatusInternalServerError)
	}

	return accounts.Success(nil, http.StatusOK)
}
In the underlying account service
Copy code
func (r *DynamoRepository) CreateAccount(ctx context.Context, account *Account) (*AccountResponse, error) {
	item, err := dynamodbattribute.MarshalMap(account)

	if err != nil {
		return nil, err
	}

	input := &dynamodb.PutItemInput{
		Item:         item,
		TableName:    aws.String(r.tableName),
		ReturnValues: aws.String("ALL_NEW"),
	}

	accountRes := AccountResponse{}
	accRes, err := r.ddb.PutItemWithContext(ctx, input)

	if err := dynamodbattribute.UnmarshalMap(accRes.Attributes, &accountRes); err != nil {
		fmt.Printf("err %#v", err)
		return nil, err
	}

	return &accountRes, nil
}
One thing i thought it could relate to is that I’m using the dynamodbiface package ( to help with mocking ) and not dynamodb?
Copy code
// DynamoRepository for creating new dynamo factory
type DynamoRepository struct {
	ddb       dynamodbiface.DynamoDBAPI
	tableName string
}
f
I see.. I’m not too familiar with Go, would it be possible if you zipped up ur repo and DM it to me?
b
Yeah sure, I’m still on my ipad at the moment but i will do that later on this evening , thank you!
f
That’d be great! It sounds like an issue somewhere in ur Go code, but I don’t know Go well enough to eyeball the issue lol
b
Lol It’s strange, the code and underlying package run ok in a hosted lambda, and i would expect an error back from the ddb call if the issue was with the input data or permissions but accRes responds with an empty struct and nothing is written to the table. But it may be that ive configured something wrong on my app that’s causing it to fail silently!
f
One thing worth trying might be to write a simple Go script to write something to ddb. If that works, see if the same code works in the SST context?
b
Yeah il setup a seperate stack tonight and see if i can get it working without the accounts package. Will try a node/ts example also to rule out my aws credentials causing the issue.
f
Hey @Bobby Ross Just wanted to see if u had a chance to figure the issue. Feel free to ping me if want to me to take a look 🤓
b
Hey @Frank apologies for the delay in responding! Busy week! On Friday i started from scratch and everything worked ok with go/ddb in a simple lambda. I’m going to have a look at the difference today and see if my underlying repo was the problem, will report back!
f
Sounds good! Glad u got it to work!