Category: node.js
-
this.query is not a function – error when using promisify with mysql
Hi everyone, I ran into the following error while attempting to promisify my node.js mysql transactions: TypeError: this.query is not a function at rollback (/var/task/node_modules/mysql/lib/Connection.js:179:15) at rollback (internal/util.js:230:26) This took a while to track down but it turns out that I needed to bind the connection after promisifying the function. Instead of: Add bind to…
-
Upload an Image to S3 Using Post and a Presigned Url
Hi everyone, Today I’ve been converting my “PUT” upload to S3 to a “POST”. The main motivator for this was to restrict the file size of uploads using a signed policy. Unfortunately this was a pretty tedious process and the error responses from S3 were very vague. Thankfully it’s working now and here’s what I…
-
4: /codebuild/output/tmp/script.sh: pip: not found – Node.js and CodeStar
Hi everyone, I ran into the following CodeBuild error after upgrading my build environment from the default nodejs8.10 to nodejs10.14: 4: /codebuild/output/tmp/script.sh: pip: not found This one was a little confusing, but thankfully fairly easy to fix. In your buildspec.yml file update the pip steps to reference pip3 instead of pip: // Original commands: #…
-
Parsing DynamoDB Items – AWS Lambda with Node.js
Hi everyone, A quick post on how to parse DynamoDB items into something more readable when using lambda with Node.js: Original: console.log(data[“Item”]); { CatBreedId: { S: ’17acbc81-2b4a-462b-be87-bcc49580b1ae’}, Name: { S: ‘Cat #1’} } Parsed: console.log(AWS.DynamoDB.Converter.unmarshall(data[“Item”])); { “CatBreedId”: “17acbc81-2b4a-462b-be87-bcc49580b1ae”, “Name”: “Cat #1” } Official doco is here: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/Converter.html Thanks to the following stackoverflow post for the…
-
Check if Running Locally – AWS SAM & NodeJS
Hi everyone, Just a quick post on how to check if code is being run locally with AWS SAM and NodeJS: // 8+ isRunningLocally = () => { return process.env.AWS_SAM_LOCAL === ‘true’; } // 6+ function isRunningLocally() { return process.env.AWS_SAM_LOCAL === ‘true’; }