Aws-sdk-js: Appsync updateApiKey does not update

Created on 2 Oct 2020  路  1Comment  路  Source: aws/aws-sdk-js

Confirm by changing [ ] to [x] below to ensure that it's a bug:

Describe the bug
NodeJs Appsync updateApiKey does not update api key expiration date, does not print any response
Is the issue in the browser/Node.js?
In Node.js
If on Node.js, are you running this on AWS Lambda?
Yes
Details of the browser/Node.js version
Node.js 12.x runtime Lambda
SDK version number
: v2.762.0

To Reproduce (observed behavior)
```const AWS = require('aws-sdk');
const moment = require('moment');

exports.lambdaHandler = async() => {
const apiId = process.env.apiId;
const appsync = new AWS.AppSync();
const region = process.env.AWS_REGION;

appsync.config.update({ region });

try {
const listParams = {
apiId
};
const response = await appsync.listApiKeys(listParams).promise();
const apiKeys = response.apiKeys;
console.log(apiKeys);
if (apiKeys && apiKeys.length) {
apiKeys.forEach(async(apiKey) => {
console.log('before', apiKey);
apiKey.expires = moment().add(1, 'month').unix();
apiKey.apiId = apiId;
console.log('modifed', apiKey);

    try {
      const updateResponse = await appsync.updateApiKey(apiKey).promise();
      console.info("Update response ", updateResponse)
    } catch (e) {
      console.error(e);
    }
  });
}

} catch (err) {
console.error(err);
throw err;
}
};

**Expected behavior**
I expect console.log to show the updated response. None is printed. I expect api key to have extended expiration.  
But if I try the same with aws cli with the printed values from "modified" in the logs, aws cli works perfectly. `appsync.updateApiKey` should behave the same.

aws appsync update-api-key --api-id=ffpvhmz6ybeijdh7sezayginzi --id=da2-fg6775vnd5cw7azxg6jvkaow3m --expires=1633182812
```

bug needs-triage

Most helpful comment

This is not a bug. This is due to my incomplete knowledge of nodejs. Replacing forEach with for-loop, my lambda works. Thanks!!

>All comments

This is not a bug. This is due to my incomplete knowledge of nodejs. Replacing forEach with for-loop, my lambda works. Thanks!!

Was this page helpful?
0 / 5 - 0 ratings