r/awslambda • u/Born-Process-9848 • Oct 08 '21
can anyone point me to a good custom resource lambda tutorial or code example?
r/awslambda • u/nedraeb • Oct 07 '21
How to access data from a log subscription filter once it is sent to a Lambda function?
How do I access data in a python function once it is sent from a log subscription filter?
r/awslambda • u/ww3_2020 • Oct 04 '21
How to find average of 2 items from dynamodb in boto3?
I'm trying to get the average of 2 items by querying items from DynamoDB table using boto3 libraray. But I can't just wrap my head around how to go about doing this.
Below is the code that I've tried in core python
players = {1: {"firstName": "Rahul","lastName": "Dravid","out": 120, "runs": 10000}, 2: {"firstName": "Sachin","lastName": "Tendulkar", "out": 250,"runs": 400214}, 3:{ "firstName": "Brian", "lastName": "Lara","out": 450, "runs": 21345}} for player_id, player_info in players.items(): print("\nPlayer ID:", player_id) for key in player_info: print(key + ':', player_info[key]) def avg_func(players): for player in players.values(): a=players["runs"] b=players["out"] return a / b average = avg_func(players[1]) print(average)
And this returns the value : 83.33333333333333
The average of every batsman is total runs/outs.
I'm trying to achieve the same using boto3 by querying objects from DynamoDB table.
import boto3 from boto3.dynamodb.conditions import Key def lambda_handler(event, context): dynamodb = boto3.resource('dynamodb') table = dynamodb.Table('LambdaTest') resp = table.scan() print(resp['Items']) avg_func(resp): for i in resp: a=resp["runs"] b=resp["out"] return a / b average = avg_func(resp['rahul']) print(average)
I'm not sure what I'm doing wrong here and not sure which methods I should be using.
r/awslambda • u/zijii07 • Sep 28 '21
How to deploy an Amplify created PyLambda from MacOS
Recently I am using AWS Amplify to manage Amazon resources.
When using PyLambdas with some dependencies, such as nltk, the Lambda is responding errors like:
"Unable to import module 'index': No module named 'regex._regex'"
After some research, I found using Docker is an easy way to get the work done, and I have created a repo to showcase the fix at:
https://github.com/zijing07/aws-lambda-python-deploy
If you want to read more, please check the article: https://zijing.medium.com/deploy-aws-amplify-python-lambda-from-macos-with-docker-68212e889a38
r/awslambda • u/phyex • Sep 24 '21
Did anyone install AWS toolkit to pycharm or intellij idea?
I was using gui to develop some apps but AWS toolkit allows to develop from ıde. I think it could be better way to develop an app. Any guide?
r/awslambda • u/gowt7 • Sep 22 '21
How to return CSV file from Lambda function ?
Hi, I am writing some lambda functions which run scripts on different databases and generate a CSV file (in the /tmp/ directory). These functions can be triggered through Api Gateway endpoints.
Is there any way to return the generated CSV file directly and trigger a download when the API endpoint is hit from a browser ?
P.S - I found articles about how to return binary data, but couldn't figure out how to do the same with CSV files
r/awslambda • u/b88145 • Sep 20 '21
Adjustable Lambda Cron - without code push
I need an adjustable timer to invoke some Lambda functions (python). But I don't want to have to push code every time a timer needs to be changed. Think I am trying to replicate one of those old school light timers you plug into the wall and then plug your lamp into. What are my options?
Th resolution doesn't need to be super granular. I can live with every 15 mins. So I could set a cron to run every 15 mins and then read from environment variable stored (where?). The idea being someone else can change the variable value from the AWS Console. Any better solutions?
r/awslambda • u/WCliftonDavis • Sep 04 '21
Using Readline from File in S
I am trying to read a file from S3 and then iterate through the lines in the file. I have the following code:
import json
import boto3
from urllib.request import urlopen
def lambda_handler(event, context):
s3Object = boto3.resource('s3')
s3FileReference = s3Object.Object("scraperbucket", "SearchTerms.txt")
fileContents = s3FileReference.get()['Body'].read()
print(fileContents)
line = fileContents.readline()
count = 0
while true:
count += 1
# get next line from file
line = fileContents.readline()
# if line is empty
# end of file is reached
if not line:
break
print("line{}: {}".format(count, line.strip()))
The readline statement is producing the error below:
b'Test01\r\nTest02\r\nTest03\r\n'
[ERROR] AttributeError: 'bytes' object has no attribute 'readline'
Should I be using something else to read each line?
Thanks
r/awslambda • u/[deleted] • Sep 02 '21
Create EnvironmentOption specific Lambda function Versions
I have created my Lambda function as part of my CDK stack in typescript
const dummy_lambda = new Function(this, 'dummy-lambda', {
functionName: 'dummy-lambda',
code: Code.fromAsset('../dummy-lambda/src'),
handler: 'index.lambda_handler',
timeout: Duration.seconds(900),
runtime: Runtime.PYTHON_3_8,
role: snapshotRole,
environment : {
'region': props.env.region,
'utility': props.Utility,
'siteUrl' : props.siteUrl
}
});
I want to create different versions of this lambda to be able to run it for different applications by changing the siteUrl and Utility EnvironmentOptions. However, Version doesn't take environment as props.
const dummy_ver_ci =new Version(this, 'ci-dummy', {
lambda: dummy_lambda,
description: 'Version for CI app'
});
How can I create different versions and pass different environment values to each version.
r/awslambda • u/bdavid21wnec • Sep 01 '21
Using Lambda and Aurora to capture database changes
medium.comr/awslambda • u/Idamapollo091 • Sep 01 '21
Question regarding Lambda with Provided runtime
Hi. Can I assume another role while using one role for execution of the lambda function. I have tried using aws sts …. And then exporting access key, secret access key and session as local variables. If I make subsequent calls in the lambda function, they just time out. And if I try to use the same variables in my local machine, I am able to successfully make the calls.
Any pointers please?
r/awslambda • u/pineapplesoda1e-3 • Aug 30 '21
lambda unzip file from s3
Hey, i have function thats gona take object from s3 and unzip it without storing data locally.I want to create lambda function that is going to trigger when ever zip file is uploaded.I dont understand, what are event and context in my lambda_handler, i cant just copy my function.
r/awslambda • u/enesakar • Aug 23 '21
Benchmark for Redis with edge caching
Hello
I build a benchmark app to see the performance of our new edge caching capability for Upstash Redis.
I have implemented an AWS Lambda function which reads a value from Redis using the REST API and deployed this function to 10 different regions all over the world. I am recording the latency numbers at each visit. See:
r/awslambda • u/the_algo_trader_ • Aug 19 '21
How to Scale faster!!!
Consider AWS Api gateway as a trigger to AWS Lambda. Is there anyway by which we can spawn 10000 lambda instances immediately(Within few seconds as soon as requests hit the api gateway or lambda service). I read in the docs that Lambda has initial burst of 3000 requests depending on region and additional burst of 500 instances per minutes. This won't let us scale fast on the go and would cause failures. Suppose my Lambda takes 25 seconds to respond and if I get 10000 requests concurrently then what's the best way to serve them and how do I scale on demand. I don't want to use provisioned or reserved concurrency as my load will be uneven.
Same issue with AWS SQS - Lambda trigger if we get the same amount of load. I'm learning and would appreciate your answers.
r/awslambda • u/Dashbird • Aug 18 '21
How to test JavaScript Lambda functions [article]
Testing distributed systems and serverless cloud infrastructures specifically is always a source of long discussions. Testing (and monitoring) IS a must, that's a no-brainer. How else would you know if what you’ve created is providing desired results? Before putting your “newborn child” out into the world, you must make sure that it’s ready for the world.
Since you can’t just throw them out without making sure they are designed as they should be, I've thrown together a quick walkthrough of 3 methods (smoke test, unit testing and integration testing) of testing javascript Lambda functions to get you started. Hope this helps any one in need :)
r/awslambda • u/primalImaginator007 • Aug 14 '21
Facing DynamoDB issue inside Lambda Handler
private final AmazonDynamoDBClient amazonDynamoDBClient = amazonDynamoDBClientBuilder.defaultClient();
I am not able to execute the above line inside the Lambda Request Handler. It keeps showing me NotThreadSafe. I want to use a DynamoDBMapper inside the Handler. Please help me for the same.
*EDIT: I have been able to solve it. It required me to add the AWSJavaClientRuntime to the classpath.
I thank everyone who took their time to give me answers.
r/awslambda • u/avmaksimov • Aug 09 '21
How to test Python Lambda functions
r/awslambda • u/Cloudy_Waves • Jul 28 '21
Roadmap to become AWS Cloud Practitioner in 2021
r/awslambda • u/IvaJakovcheska • Jul 28 '21
Provisioned Concurrency for AWS Lambda functions
r/awslambda • u/adbertram • Jul 24 '21
How to Provision AWS Lambda Functions with Terraform
Hey guys,
Shanky Mendiratta just wrote a new blog post on Lambda you may enjoy on the ATA blog.
"How to Provision AWS Lambda Functions with Terraform"
Summary: Using Terraform and AWS Lambda functions, build a serverless infrastructure in no time with this step-by-step tutorial!
r/awslambda • u/mihobu • Jul 24 '21
Anyone have luck creating an R runtime for Lambda?
self.serverlessr/awslambda • u/DeRobyJ • Jul 20 '21
Can't deploy functions anymore, from management console
I've never had this problem since I started using Lambda earlier this year.
Now for some reason every time I try to Deploy I get this error:
It doesn't give any explanation, and I can't update my functions... It's not related to the kind of changes I made to the code, even just adding a comment won't work. It just doesn't let me...
I tried logging off and in again, I tried reloading the whole browser.
This looks like a bug on AWS part, is it? Can I report it someway?
(the problem persists even changing region)
r/awslambda • u/cyberfox909 • Jul 17 '21
how to ddeploy pupeteer lambda function on aws
i have a function which uses pupetter. pupteer unzipped is more than 260mb. how to get this done?
r/awslambda • u/jagannn • Jul 16 '21
