Tag: AWS

  • Get User Id in Lambda node.js

    Hi everyone, A quick post on where to find the user id (sub) in a lambda requested that has been authenticated with a congito authorizer. You’ll be able to find everything you need in the event object under requestContext > authorizer > claims:

  • Cognito Auth with AWS SAM

    Hi everyone, I’ve spent today implementing Cognito with AWS SAM and it took quite a while to work out what needed to be done – unfortunately there’s a lot of conflicting doco out there. Posting a sample template just in case it’s able to help anyone else out. The first thing to do is to…

  • AWS SAM not re-creating DynamoDb Table that was manually deleted – CodeStar

    Hi everyone, I ran into a bit of an issue after deleting a DynamoDb table via the AWS Console that had been created via CloudFormation (using AWS SAM). After deleting it I had expected it to be re-created automatically on the next deploy. Unfortunately this didn’t happen. I came across the following AWS article that…

  • mocha tests/* sh: 1: mocha: Permission denied – AWS CodeBuild with Node.js

    Hi everyone, I ran into the following error while running a Node.js build with AWS CodeBuild: mocha tests/* sh: 1: mocha: Permission denied To resolve this I removed node_modules from my repository and added it to .gitignore: node_modules/ Thanks to the following links for the info: Add node_modules to gitignore: https://stackoverflow.com/a/29820869/522859 Misc background issues: https://github.com/mochajs/mocha/issues/1487

  • 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…

  • Create DynamoDB Table – AWS CLI

    Hi everyone, A quick example of how to create a dynamodb table using the AWS CLI: aws dynamodb create-table –table-name CatBreeds –attribute-definitions AttributeName=CatBreedId,AttributeType=S –key-schema AttributeName=CatBreedId,KeyType=HASH –provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5 For more info the following AWS page helped me: https://docs.aws.amazon.com/cli/latest/reference/dynamodb/create-table.html

  • 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’; }

  • AWS IoT – error in discovery certificate_verify_failed

    Hi everyone, I ran into the following error while using the AWS IoT python SDK: Error in discovery! Type: Error message: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:720) It turns out that this was because I was using the wrong root certificate. In the documentation there are five certificates listed: RSA 2048 bit key: VeriSign Class…

  • AWS 2_ContinuousDeliveryPipeline Tutorial – Error: no test specified

    Hi everyone, I ran into the following error while completing an AWS tutorial: https://github.com/aws-samples/aws-serverless-workshops/tree/master/DevOps/2_ContinuousDeliveryPipeline C:UsersChris-PCsourcereposUniApiuni-apitest>npm test > uni-api-test@1.0.0 test C:UsersChris-PCsourcereposUniApiuni-api > echo ‘Error: no test specified’ ‘Error: no test specified’ The solution was to add the following line to my package.json file: “scripts”: {“test”: “mocha”} Now when running npm test I get the expected test…

  • Parsing Hash Args for Cognito Auth – Javascript

    Hi everyone, A quick post on a function for parsing hash args when using AWS Congito. //jsfiddle.net/4eo7836j/embed/ Just in case the fiddle ever disappears: const parseHashArgs = aURL => { aURL = aURL || window.location.href; var vars = {}; var hashes = aURL.slice(aURL.indexOf(‘#’) + 1).split(‘&’); for (var i = 0; i 1) { vars[hash[0]] =…

Create a website or blog at WordPress.com