Category: Lambda
-
Adding a Custom Domain Name – AWS SAM
Hi everyone, It’s been a long time but I’m messing around with AWS SAM again. I’m currently converting www.testerwidgets.com into an AWS SAM application. As part of this I needed to add a custom domain. Unfortunately, the doco on how to do this isn’t great so I’m going to share what ended up working for…
-
Access to fetch from origin has been blocked by CORS policy – AWS SAM Local
Hi everyone, I’ve been using AWS SAM local lately and ran into a bit of an issue with CORS. It took a looong time to find a solution that worked for all of my local scenarios so hopefully this will be able to help someone else out. Access to fetch at ‘http://127.0.0.1:3000’ from origin ‘http://localhost:3001’…
-
Overriding Global Variables – AWS SAM Local
Hi everyone, Today I’ve added local overrides to the global variables in my template.yml file. This was pretty finicky – a lot of conflicting suggestions out there unfortunately. These are the settings that ended up working for me. local-env-var-overrides.json: template.yaml aws sam local command: create.js This link ended up being pretty useful: https://www.npmjs.com/package/aws-sam-local
-
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:
-
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’; }
-
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…
-
An error occurred (UnrecognizedClientException) when calling the CreateFunction operation: The security token included in the request is invalid.
Hi everyone, I ran into the following error today while attempting to create a Lambda function using the CLI: An error occurred (UnrecognizedClientException) when calling the CreateFunction operation: The security token included in the request is invalid. The first thing to check is that your aws config is setup correctly. For me this is under…