1

I have two use cases I'm using DynamoDB locally with nodejs and I can create/read/update/delete successfully, no problems

But when I'm using DynamoDB with a lambda configured with a template.yml and with ASW Policies to read create update etc, I can't get response from DynamoDB, I just didn't enter in the callback

Here is the code :

    AWS.config.update({
      region: "eu-central-1",
    });

    var dynamo = new AWS.DynamoDB.DocumentClient();

    console.log(`[TDF-Rankings] - Trying to put datas in db`);

    dynamo.put({
      TableName: 'tdf-rankings-dev',
      Item: {
        id: uuid(`${Checkpoint.rank_type}.${Checkpoint.season}.${checkpoint.type}.${Checkpoint.number}`),
        ...Checkpoint
        }
    }, (err, res) => {
      console.log(`[TDF-Rankings] - in the callback`);
      if(err){
        console.log(err);
        return err
      }
      console.log(res);
      return res
    })

The logs :

START RequestId: 1e4fb8f0-e081-106d-5c24-58fa931a5892 Version: $LATEST
2020-02-21T18:53:34.820Z        1e4fb8f0-e081-106d-5c24-58fa931a5892    INFO    [TDF-Rankings] - Trying to put datas in db
END RequestId: 1e4fb8f0-e081-106d-5c24-58fa931a5892
REPORT RequestId: 1e4fb8f0-e081-106d-5c24-58fa931a5892  Init Duration: 661.36 ms        Duration: 25.35 ms      Billed Duration: 100 ms Memory Size: 128 MB     Max Memory Used: 60 MB

But if I do this :

    AWS.config.update({
      region: "eu-central-1",
    });

    var dynamo = new AWS.DynamoDB.DocumentClient();

    console.log(`[TDF-Rankings] - Trying to put datas in db`);

    const request = dynamo.put({
      TableName: 'tdf-rankings-dev',
      Item: {
        id: uuid(`${Checkpoint.rank_type}.${Checkpoint.season}.${checkpoint.type}.${Checkpoint.number}`),
        ...Checkpoint
        }
    }, (err, res) => {
      console.log(`[TDF-Rankings] - in the callback`);
      if(err){
        console.log(err);
        return err
      }
      console.log(res);
      return res
    })

    console.log(request);
    
I get this

START RequestId: 86bf81b5-687b-127c-07ec-c586c9b6fcae Version: $LATEST
2020-02-21T19:04:01.139Z        86bf81b5-687b-127c-07ec-c586c9b6fcae    INFO    [TDF-Rankings] - Trying to put datas in db
2020-02-21T19:04:01.192Z        86bf81b5-687b-127c-07ec-c586c9b6fcae    INFO    Request {
  domain: null,
  service:
   Service {
     config:
      Config {
        credentials: [EnvironmentCredentials],
        credentialProvider: [CredentialProviderChain],
        region: 'eu-central-1',
        logger: null,
        apiVersions: {},
        apiVersion: null,
        endpoint: 'dynamodb.eu-central-1.amazonaws.com',
        httpOptions: [Object],
        maxRetries: undefined,
        maxRedirects: 10,
        paramValidation: true,
        sslEnabled: true,
        s3ForcePathStyle: false,
        s3BucketEndpoint: false,
        s3DisableBodySigning: true,
        s3UsEast1RegionalEndpoint: 'legacy',
        s3UseArnRegion: undefined,
        computeChecksums: true,
        convertResponseTypes: true,
        correctClockSkew: false,
        customUserAgent: null,
        dynamoDbCrc32: true,
        systemClockOffset: 0,
        signatureVersion: 'v4',
        signatureCache: true,
        retryDelayOptions: {},
        useAccelerateEndpoint: false,
        clientSideMonitoring: false,
        endpointDiscoveryEnabled: false,
        endpointCacheSize: 1000,
        hostPrefixEnabled: true,
        stsRegionalEndpoints: 'legacy' },
     isGlobalEndpoint: false,
     endpoint:
      Endpoint {
        protocol: 'https:',
        host: 'dynamodb.eu-central-1.amazonaws.com',
        port: 443,
        hostname: 'dynamodb.eu-central-1.amazonaws.com',
        pathname: '/',
        path: '/',
        href: 'https://dynamodb.eu-central-1.amazonaws.com/' },
     _events: { apiCallAttempt: [Array], apiCall: [Array] },
     MONITOR_EVENTS_BUBBLE: [Function: EVENTS_BUBBLE],
     CALL_EVENTS_BUBBLE: [Function: CALL_EVENTS_BUBBLE],
     _clientId: 1 },
  operation: 'putItem',
  params:
   { TableName: 'tdf-rankings-dev',
     Item:
      { id: [Object],
        rank_type: [Object],
        season: [Object],
        stage_id: [Object],
        stage: [Object],
        name: null,
        km: [Object],
        ranks: [Object] } },
  httpRequest:
   HttpRequest {
     method: 'POST',
     path: '/',
     headers:
      { 'User-Agent':
         'aws-sdk-nodejs/2.585.0 linux/v10.18.0 exec-env/AWS_Lambda_nodejs10.x callback',
        'Content-Type': 'application/x-amz-json-1.0',
        'X-Amz-Target': 'DynamoDB_20120810.PutItem',
        'X-Amz-Content-Sha256':
         'c19835b2095ecfc493cbb8bab91423932ab0db31b061278f6fa4e845d539c141',
        'Content-Length': 3461,
        Host: 'dynamodb.eu-central-1.amazonaws.com',
        'X-Amz-Date': '20200221T190401Z',
        Authorization:
         'AWS4-HMAC-SHA256 Credential=AKIAV2CIO56THGYBA35E/20200221/eu-central-1/dynamodb/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date;x-amz-target, Signature=7d1f4ef387e346d364f5021ebfd2e0365c5dffa6d18f66f6c924dbf85af5d650' },
     body:
      '{"TableName":"tdf-rankings-dev","Item":{"id":{"S":"79fe14cd-2a5a-577d-a011-5100af8e0193"},"rank_type":{"S":"ETG"},"season":{"N":"2019"},"stage_id":{"S":"68169852-8d13-521b-bd50-fc7eece13b4a"},"stage":{"S":"1400"},"km":{"N":"2319.3"},"ranks":{"L":[{"M":{"bib":{"N":"7"},"position":{"N":"1"},"penality":{"N":"0"},"rider_id":{"S":"db4e117f-7b52-5819-a80d-31ed011064be"},"time":{"N":"0"}}},{"M":{"bib":{"N":"14"},"position":{"N":"2"},"penality":{"N":"0"},"rider_id":{"S":"db4e117f-7b52-5819-a80d-31ed011064be"},"time":{"N":"665000"}}},{"M":{"bib":{"N":"2"},"position":{"N":"3"},"penality":{"N":"0"},"rider_id":{"S":"db4e117f-7b52-5819-a80d-31ed011064be"},"time":{"N":"1510000"}}},{"M":{"bib":{"N":"9"},"position":{"N":"4"},"penality":{"N":"0"},"rider_id":{"S":"db4e117f-7b52-5819-a80d-31ed011064be"},"time":{"N":"1629000"}}},{"M":{"bib":{"N":"1"},"position":{"N":"5"},"penality":{"N":"0"},"rider_id":{"S":"db4e117f-7b52-5819-a80d-31ed011064be"},"time":{"N":"1905000"}}},{"M":{"bib":{"N":"6"},"position":{"N":"6"},"penality":{"N":"0"},"rider_id":{"S":"db4e117f-7b52-5819-a80d-31ed011064be"},"time":{"N":"1947000"}}},{"M":{"bib":{"N":"11"},"position":{"N":"7"},"penality":{"N":"0"},"rider_id":{"S":"db4e117f-7b52-5819-a80d-31ed011064be"},"time":{"N":"2342000"}}},{"M":{"bib":{"N":"13"},"position":{"N":"8"},"penality":{"N":"0"},"rider_id":{"S":"db4e117f-7b52-5819-a80d-31ed011064be"},"time":{"N":"2720000"}}},{"M":{"bib":{"N":"10"},"position":{"N":"9"},"penality":{"N":"0"},"rider_id":{"S":"db4e117f-7b52-5819-a80d-31ed011064be"},"time":{"N":"2774000"}}},{"M":{"bib":{"N":"4"},"position":{"N":"10"},"penality":{"N":"0"},"rider_id":{"S":"db4e117f-7b52-5819-a80d-31ed011064be"},"time":{"N":"3126000"}}},{"M":{"bib":{"N":"8"},"position":{"N":"11"},"penality":{"N":"0"},"rider_id":{"S":"db4e117f-7b52-5819-a80d-31ed011064be"},"time":{"N":"3427000"}}},{"M":{"bib":{"N":"3"},"position":{"N":"12"},"penality":{"N":"0"},"rider_id":{"S":"db4e117f-7b52-5819-a80d-31ed011064be"},"time":{"N":"4278000"}}},{"M":{"bib":{"N":"15"},"position":{"N":"13"},"penality":{"N":"0"},"rider_id":{"S":"db4e117f-7b52-5819-a80d-31ed011064be"},"time":{"N":"5659000"}}},{"M":{"bib":{"N":"5"},"position":{"N":"14"},"penality":{"N":"0"},"rider_id":{"S":"db4e117f-7b52-5819-a80d-31ed011064be"},"time":{"N":"6049000"}}},{"M":{"bib":{"N":"20"},"position":{"N":"15"},"penality":{"N":"0"},"rider_id":{"S":"db4e117f-7b52-5819-a80d-31ed011064be"},"time":{"N":"6892000"}}},{"M":{"bib":{"N":"22"},"position":{"N":"16"},"penality":{"N":"0"},"rider_id":{"S":"db4e117f-7b52-5819-a80d-31ed011064be"},"time":{"N":"7278000"}}},{"M":{"bib":{"N":"21"},"position":{"N":"17"},"penality":{"N":"0"},"rider_id":{"S":"db4e117f-7b52-5819-a80d-31ed011064be"},"time":{"N":"7532000"}}},{"M":{"bib":{"N":"12"},"position":{"N":"18"},"penality":{"N":"0"},"rider_id":{"S":"db4e117f-7b52-5819-a80d-31ed011064be"},"time":{"N":"7740000"}}},{"M":{"bib":{"N":"16"},"position":{"N":"19"},"penality":{"N":"0"},"rider_id":{"S":"db4e117f-7b52-5819-a80d-31ed011064be"},"time":{"N":"9484000"}}},{"M":{"bib":{"N":"17"},"position":{"N":"20"},"penality":{"N":"0"},"rider_id":{"S":"db4e117f-7b52-5819-a80d-31ed011064be"},"time":{"N":"9499000"}}},{"M":{"bib":{"N":"18"},"position":{"N":"21"},"penality":{"N":"0"},"rider_id":{"S":"db4e117f-7b52-5819-a80d-31ed011064be"},"time":{"N":"11056000"}}},{"M":{"bib":{"N":"19"},"position":{"N":"22"},"penality":{"N":"0"},"rider_id":{"S":"db4e117f-7b52-5819-a80d-31ed011064be"},"time":{"N":"13628000"}}}]}}}',
     endpoint:
      Endpoint {
        protocol: 'https:',
        host: 'dynamodb.eu-central-1.amazonaws.com',
        port: 443,
        hostname: 'dynamodb.eu-central-1.amazonaws.com',
        pathname: '/',
        path: '/',
        href: 'https://dynamodb.eu-central-1.amazonaws.com/',
        constructor: [Function] },
     region: 'eu-central-1',
     _userAgent:
      'aws-sdk-nodejs/2.585.0 linux/v10.18.0 exec-env/AWS_Lambda_nodejs10.x callback',
     stream:
      ClientRequest {
        domain: null,
        _events: [Object],
        _eventsCount: 7,
        _maxListeners: undefined,
        output: [Array],
        outputEncodings: [Array],
        outputCallbacks: [Array],
        outputSize: 4111,
        writable: true,
        _last: false,
        chunkedEncoding: false,
        shouldKeepAlive: true,
        useChunkedEncodingByDefault: true,
        sendDate: false,
        _removedConnection: false,
        _removedContLen: false,
        _removedTE: false,
        _contentLength: 3461,
        _hasBody: true,
        _trailer: '',
        finished: true,
        _headerSent: true,
        socket: null,
        connection: null,
        _header:
         'POST / HTTP/1.1\r\nUser-Agent: aws-sdk-nodejs/2.585.0 linux/v10.18.0 exec-env/AWS_Lambda_nodejs10.x callback\r\nContent-Type: application/x-amz-json-1.0\r\nX-Amz-Target: DynamoDB_20120810.PutItem\r\nX-Amz-Content-Sha256: c19835b2095ecfc493cbb8bab91423932ab0db31b061278f6fa4e845d539c141\r\nContent-Length: 3461\r\nHost: dynamodb.eu-central-1.amazonaws.com\r\nX-Amz-Date: 20200221T190401Z\r\nAuthorization: AWS4-HMAC-SHA256 Credential=AKIAV2CIO56THGYBA35E/20200221/eu-central-1/dynamodb/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date;x-amz-target, Signature=7d1f4ef387e346d364f5021ebfd2e0365c5dffa6d18f66f6c924dbf85af5d650\r\nConnection: keep-alive\r\n\r\n',
        _onPendingData: [Function: noopPendingOutput],
        agent: [Agent],
        socketPath: undefined,
        timeout: undefined,
        method: 'POST',
        path: '/',
        _ended: false,
        res: null,
        aborted: undefined,
        timeoutCb: [Function: emitRequestTimeout],
        upgradeOrConnect: false,
        parser: null,
        maxHeadersCount: null,
        didCallback: false,
        [Symbol(isCorked)]: false,
        [Symbol(outHeadersKey)]: [Object] } },
  startTime: 2020-02-21T19:04:01.141Z,
  response:
   Response {
     request: [Circular],
     data: null,
     error: null,
     retryCount: 0,
     redirectCount: 0,
     httpResponse:
      HttpResponse {
        statusCode: undefined,
        headers: {},
        body: undefined,
        streaming: false,
        stream: null,
        _abortCallback: [Function: callNextListener] },
     maxRetries: 10,
     maxRedirects: 10,
     nextPage: [Function] },
  _asm:
   AcceptorStateMachine {
     currentState: 'send',
     states:
      { validate: [Object],
        build: [Object],
        afterBuild: [Object],
        sign: [Object],
        retry: [Object],
        afterRetry: [Object],
        send: [Object],
        validateResponse: [Object],
        extractError: [Object],
        extractData: [Object],
        restart: [Object],
        success: [Object],
        error: [Object],
        complete: [Object] } },
  _haltHandlersOnError: false,
  _events:
   { validate:
      [ [Function],
        [Function],
        [Function],
        [Function: VALIDATE_REGION],
        [Function: BUILD_IDEMPOTENCY_TOKENS],
        [Function: VALIDATE_PARAMETERS] ],
     afterBuild:
      [ [Function],
        [Function: SET_CONTENT_LENGTH],
        [Function: SET_HTTP_HOST] ],
     restart: [ [Function: RESTART] ],
     sign: [ [Function], [Function], [Function] ],
     validateResponse: [ [Function: VALIDATE_RESPONSE], [Function] ],
     send: [ [Function] ],
     httpHeaders: [ [Function: HTTP_HEADERS] ],
     httpData: [ [Function: HTTP_DATA] ],
     httpDone: [ [Function: HTTP_DONE] ],
     retry:
      [ [Function: FINALIZE_ERROR],
        [Function: INVALIDATE_CREDENTIALS],
        [Function: EXPIRED_SIGNATURE],
        [Function: CLOCK_SKEWED],
        [Function: REDIRECT],
        [Function: RETRY_CHECK],
        [Function: API_CALL_ATTEMPT_RETRY] ],
     afterRetry: [ [Function] ],
     build: [ [Function: buildRequest] ],
     extractData:
      [ [Function: extractRequestId],
        [Function: checkCrc32],
        [Function: extractData],
        [Function] ],
     extractError: [ [Function: extractError], [Function: extractRequestId] ],
     httpError: [ [Function: ENOTFOUND_ERROR] ],
     success: [ [Function: API_CALL_ATTEMPT] ],
     complete: [ [Function: API_CALL], [Function] ] },
  emit: [Function: emit],
  API_CALL_ATTEMPT: [Function: API_CALL_ATTEMPT],
  API_CALL_ATTEMPT_RETRY: [Function: API_CALL_ATTEMPT_RETRY],
  API_CALL: [Function: API_CALL],
  rawParams:
   { TableName: 'tdf-rankings-dev',
     Item:
      { id: '79fe14cd-2a5a-577d-a011-5100af8e0193',
        rank_type: 'ETG',
        season: 2019,
        stage_id: '68169852-8d13-521b-bd50-fc7eece13b4a',
        stage: '1400',
        name: undefined,
        km: 2319.3,
        ranks: [Array] } },

Great thanks if you can Help it's for Tour de france 2020, that begin in 5 month but end to end test are next week

1
  • Is your entry point function async? Commented Feb 21, 2020 at 19:46

2 Answers 2

1

add a .promise() after the closing parenthesis of dynamo.put

e.g dynamo.put(...).promise()

Sign up to request clarification or add additional context in comments.

Comments

0

If your lambda is using async as entry point
you need to add promise in the end of the dynamoDB object such as dynamo.put(...).promise()

exports.handler =  async function(event, context) {
    const result = await dynamo.put(...).promise()
    console.log(result)
    return {....} // trigger response
}

If you lambda is not using async as entry point
you need to use callback style

exports.handler = function(event, context, callback) {
    dynamodb.put(..., function(result){
        console.log(result);
        callback() // ---> trigger response 
    })
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.