Skip to main content

Posts

Showing posts from September, 2018

API GATEWAY: THE CLOUDFRONT 403 FORBIDDEN ERROR

If you are having a 403 Forbidden error from CloudFront , that means your domain name is not linked to your CloudFront distribution and because CloudFront stays in front of your API GATEWAY you need to create a CNAME record pointing your domain name to your CloudFront target domain name in order for it to work. So, If you need to point your api to a custom domain name, all you have to do is following those 2 easy steps: 1 - CREATING YOUR CUSTOM DOMAIN NAME Go to the API GATEWAY console and click on the Custom Domain Name menu. Click on the Create Custom Domain Name button. Next, assign a certificate matching the same domain name you are creating and map to the root path and destination of your desired api. Lastly, copy the CloudFront Target Domain Name . You will need to paste that in your Route 53 record. 2 - CREATING A CNAME RECORD ON ROUTE 53 Create a CNAME record on Route 53 for the same custom domain name, assigning to it the CloudFront Target Domain. CONCLUSION

Getting to know the S3 Event Object

In this post i am going to show you how you can get into the content of the file that trigged your lambda. As we have seen in the previous post, the event object is passed as an argument to our lambda function, like this: exports.handler = (event, context, callback) => { }; When you place a trigger on a Lambda function based on a S3 event, S3 will pass all the context information that you need inside of the event object. In this case, our lambda will be trigged by an S3 event and the event object that will be passed to it will have a Record property with an array of objects inside of it like is shown below: { "event":{ "Records":[ { "eventVersion":"2.0", "eventSource":"aws:s3", "awsRegion":"us-east-1", "eventTime":"2018-09-22T14:25:20.411Z", "eventName":"ObjectCreated:Put&

Getting to know the Lambda Event Object

With any kind of http request, being it a simple web server or an api gateway, we will usually need to log different kind of information regarding the received request. But how can we do that with Lambda and how can we get all available information from it? Thats when the event object comes in place. The API GATEWAY will send all information about the request encapsulated in the event object passing it as an argument to our lambda function, like this: exports.handler = (event, context, callback) => { }; The event object have the following nested objects as shown below: 1. resource 2. path 3. httpMethod 4. headers 5. multiValueHeaders 6. queryStringParameters 7. multiValueQueryStringParameters 8. pathParameters 9. stageVariables 10. requestContext 11. body 12. isBase64Encoded { "resource": "/", "path": "/", "httpMethod": "GET", "headers": {}, "multiValueHe

API Gateway Integration with Lambda : How to get all querystrings params

If you stringify the event you will notice that the queryStringParameters is actually an object rather than an array. So in order to get all queryStrings params passed in an API Gateway request you can simply make a for each key value pair in the object like this: var element = {}; for (var key in event.queryStringParameters) { element[key] = event.queryStringParameters[key]; }