Trying to connect to DynamoDB

Hello there!

I'm trying to get a Swift Lambda to connect to DynamoDB, using the code from this PR:

The error I'm getting when invoking the lambda is this:

START RequestId: 7061eaef-c9ac-4fd4-a941-860f0ef093c5 Version: $LATEST
2020-06-05T22:13:17+0000 info: lambda lifecycle starting with Configuration
  General(logLevel: info))
  Lifecycle(id: 1631261120541, maxTimes: 0, stopSignal: TERM)
  RuntimeEngine(ip: 127.0.0.1, port: 9001, keepAlive: true, requestTimeout: nil
2020-06-05T22:13:17+0000 info: credentials.source=environment 'AWS_CONTAINER_CREDENTIALS_RELATIVE_URI' environment variable not specified. Rotating credentials not available.
2020-06-05T22:13:17+0000 warning: lifecycleId=1631261120541 reporting initialization error to lambda runtime engine using /2018-06-01/runtime/init/error
2020-06-05T22:13:18+0000 info: shutdown completed
END RequestId: 7061eaef-c9ac-4fd4-a941-860f0ef093c5
REPORT RequestId: 7061eaef-c9ac-4fd4-a941-860f0ef093c5	Duration: 2462.78 ms	Billed Duration: 2500 ms	Memory Size: 128 MB	Max Memory Used: 36 MB	
Unknown application error occurred

I've configured an AIM role with permissions for DynamoDB, and assigned it to the Lambda. I'm not sure what to do next. Any help would be appreciated.

Thanks!
Eneko

cc @tachyonics

There are a couple of things you can do to dig deeper into what is going on.

The issue could be either when getting the credentials from the Lambda environment or when trying to call DynamoDb. The easiest way to determine this is to change your logging level to debug. If credentials are successfully being obtained from the Lambda environment, you should see this log line-

If this is happening then it is likely the issue is when trying to call DynamoDB. For this we will need to try and get a descriptive error message.

In general, debug logging should provide more information which might give this to us.

Alternatively, the error may be being send back as the result of the Lambda. Are you running the Lambda in the AWS console? If so, do you see a result?

Hi @tachyonics, thanks for the feedback. This issue is when using deploy.sh to manually deploy the lambda function. If I use sam-deploy.sh, everything works as expected.

Not sure which piece of the configuration I'm missing. Where should these environment variables be configured?

private struct EnvironmentVariables {
  static let dynamoEndpointHostName = "DYNAMO_ENDPOINT_HOST_NAME"
  static let dynamoTableName = "DYNAMO_TABLE_NAME"
  static let region = "AWS_REGION"
}

Currently, I'm getting:

{
  "errorType": "InitializationError",
  "errorMessage": "missingEnvironmentVariable(reason: \"\\'DYNAMO_ENDPOINT_HOST_NAME\\' environment variable not specified.\")"
}

Thanks!

Never mind, just found the place in the Lambda configuration page :man_facepalming:

Just got it working :tada:, thanks for the help!

This is something I overlooked for the deploy.sh script.

@tomerd For the deploy.sh it looks like an AWS CLI call to update function configuration[1] is needed to set environment variables. Do you have any preference to how the variables are specified as input?

[1] update-function-configuration — AWS CLI 1.25.78 Command Reference

@tachyonics no strong preference. do you have a suggestion as how you would want to do that?