---
# System prepended metadata

title: Lambda and SQS

---

# Lambda and SQS
---

## Serverless computing


![Lambda](https://i.imgur.com/v0JoMii.png)


* AWS Lambda is a compute service that enables you to run code without provisioning or managing servers.

Before using AWS Lambda, must have an understanding of key Lambda concepts: 
* Event source – what triggers the call 
* Language choice
* Execution environment – permissions and resources


### BAD Part of Lambda

* Load time (not able to run the code instantanious *especially __JAVA__*
* More interpretation time for JS compare to JAVA
* __Function is deployed at region level__
* Lambda function requirements
    * FunctionName
    * Runtime Language
    * Permissions
        * default is set to create a new role
        * IMP part:  Role needs to have permissions to write logs to cloudwatch
        * For Python, JS we can open it in cloud 9

### Lambda is mainly useful in microservices architecture

```python
def Lambda_handler(event, context):
    return {
    'message': "Hello World",
    sratusCode: 200,
 }
```
* it does have access upto 500mb storage size
* it keeps it for upto 15 mins

![](https://i.imgur.com/FETC37w.png)

---
![](https://i.imgur.com/a10AHPm.png)



![](https://i.imgur.com/eXlU6e6.png)

### PERMISSIONS
* Invocation permission: invocation permission needs to be provided to other resourcecs to invoke lambda
* Execution permission: Lambda needs exec permission to access other resourcecs
* by default lambda doesnt have any access. 
* Push model: Invoketion and execution permissions
    * update access policy associated with your lambda function
    * it provides the addOermission API
* Pull model : execution permissions
    * Grant AWS Lambda permission to read from the stream
    * update the execution role
* **Pull only works with dynamodb stream or kinesis** 
* RequestResponse: direct invoke

* All calls are limited to 15 mins (900 sec) of running time
* Default timeout is 3 seconds but can be set to anything from 1 to 900 seconds
* Duration is calculated from the time your code begins executing until it returns or terminate
* TCP Port 25 is blocked by default (we cannot execute an email)
* only tcp/ip sockets are supported (only inbound)
* there is only ipv4 (no ipv6)
* there is no swap memory
* Max memory is 3008MB (3gb)
* Lambda functions are immutable
* Every time we update the fucntion it creates a new versions
* We switch the alias from dev to prod to point to the latest version of lambda functions
* Building a deployment packge
    * __Max size 250MB__

### Best practices
![](https://i.imgur.com/4w5sUpd.png)

---

# SQS

---

![](https://i.imgur.com/xmCi5oz.png)
* We can hold the message for upto 14 days
---

# SNS

---

![](https://i.imgur.com/lRB0VOx.png)

* SNS follows the “publish-subscribe” (pub-sub) messaging paradigm, with notifications being delivered to clients using a “push” mechanism that eliminates the need to periodically check or “poll” for new information and updates.

![](https://i.imgur.com/HZQVJjM.png)
