Given the following Code
var base64 = ''
const AWS = require('aws-sdk')
let awsConfig = {
'region': 'us-west-2',
'endpoint': 'http://dynamodb.us-west-2.amazonaws.com',
'accessKeyId': 'ABCDEFGHIJKLMANOPQRSTUVWXYZ',
'secretAccessKey': 'ABCDABSDJFGJALGJADSLGJALKDJGALKSDJGLA'
}
AWS.config.update(awsConfig)
let docClient = new AWS.DynamoDB.DocumentClient()
let fetchOneByKey = function () {
var params = {
TableName: 'test',
Key: {
'key1': 'abc'
}
}
docClient.get(params, function (err, data) {
if (err) {
console.log('test::fetchOneByKey::error - ' + err)
} else {
base64 = data.Item.b.toString('base64')
}
})
}
fetchOneByKey()
console.log(base64)
For some reason my variable base64
prints nothing. This is weird because when I do console.log(data.Item.b.toString('base64')
it prints the base64
string so i know the data is not empty for sure.
For some reason my variable is not getting updated and I am not sure why. I am clearly calling the function fetchOneByKey()
so in theory base64
should get updated but it is not.