Lambda functions

 Lambda functions


Lambda is special service in AWS makes event-driven development much more accessible and easier. Lambda allows you to execute function after some kind of event. 

Let's see this in action, so that would be more easier to understand. So what I will do is, I will create a lambda function which will be triggered when someone do some operation on my S3 bucket then it will log a simple message.

  1. First need to search lambda in dashboard





  2. We have to set our runtime here, Please select any Python runtime  




  3. We will use this code block

    import json
    import logging

    logger = logging.getLogger()
    logger.setLevel(logging.INFO)

    def lambda_handler(event, context):
    logger.info("Python is awesome")

    return {
    'statusCode': 200,
    'body': 'Log entry created'
    }

  4.  After pasting here, click to deploy code button





  5. We have to set permissions first. As you might already know that all services in AWS are segregated in terms of access. So we need to attach policy to current role. Click to the role.



  6. And attach policy S3ReadOnlyAccess.




  7. Add trigger.




  8. Select S3 service and your bucket (I assume you created bucket for this purpose but any bucket will work just fine).




  9. And after completing steps above you need to either delete or upload something to that bucket.

  10. Lastly in order to see the result we need to check CloudWatch.











Comments

Popular posts from this blog

S3 - Create a static website

AWS - Databases DynamoDB, RDS

S3