r/awslambda • • Apr 17 '21

Connection pooling issue Lambda loading data to PostgreSql

2 Upvotes

Hello , If anyone has any advice on resolving connection pooling problems with Lambdas . We have Lambdas that load large datasets into PostgreSql , each Lambda has to authenticate using IAM to load the data which results in each Lambda connection opened is a new one , so connection pooling doesn't work and the max connection limit is reached . Would a better approach be to use the AWS Data Migration Service to load the data , instead of Lambda functions ? Thanks for any comments


r/awslambda • • Apr 13 '21

uploading and extracting a compressed html file

2 Upvotes

Hey all, wanting to know if anyone can help me.

I've created a zip of an html file, and I have a (python) Lambda function to extract the zip file archive and place the contents into the S3 bucket.

It's 'sort-of' working, however the html files ends up with metadata Content-Type as binary/octet-stream. So when access the file via URL (it's public), instead of opening the file like an HTML page, it tried to download it.

If I upload the HTML file manually, it works as expected.

Does anybody know what I'm doing wrong. I can post the Lambda function I'm using, but I suspect it's not right anyway (copy/paste from online).

Cheers!!

Edit: figured it out myself. Have posted code as comment for future reference


r/awslambda • • Apr 04 '21

How I can trigger aws lambda function externally for gitlab container registry

2 Upvotes

Actually I am working on server-less project I need little assistance and way out for my problems.

I have my php docker image in gitlab container registry and now I need to trigger that image container using aws lambda function. Can anyone help me to achieve this ? How I can trigger external gitlab container registry from aws lambda function?


r/awslambda • • Jan 28 '21

Video: How to configure an AWS Lambda Policy within a Gravitee.io API - Gravitee API Platform

Thumbnail
gravitee.io
2 Upvotes

r/awslambda • • Jan 27 '21

Dynamically change Lambda Configuration?

2 Upvotes

I was wondering if it was possible to update/change the Lambda's configuration (# of CPUs, amount of RAM) at runtime?

For my situation, I have two lambdas that "process" a file on S3. The file can vary drastically in size, think 100KB to 300 MB.

The first lambda does some very lightweight enhancement to the file and then kicks off the second lambda. The second lambda does more heavy duty processing that is heavily affected by the file's size.

I'd like to figure out a way to dynamically change the second lambda's config based off the size of the file. Has anybody done something like this before? Any tips/tricks?

Right now, I'm thinking of creating several "lambda2" functions with different sized configurations and then having lambda 1 kick off a specific "configuration" of lambda2 based off the incoming file size. This feels clunky but it would probably work.


r/awslambda • • Jan 25 '21

Copy AWS Snapshot to S3 bucket

2 Upvotes

I am looking to build a lambda function as part of a forensics workflow that will copy a particular EBS snapshot to a manually created S3 bucket in order to store for short/long term forensics requirements. Looking for any pointers!


r/awslambda • • Jan 19 '21

Locally importing, editing, and debugging Lambda Functions with the AWS Toolkit for Cloud9

2 Upvotes

AWS Cloud9 is making an update to its UI. They removed a tab called "AWS Resources" which allowed you to import and upload changes to your lambda functions. It also would create a

When enabled, AWS Toolkit replaces the AWS Resources window for working with Lambda functions and serverless apps. On January 31, 2021, 00:00 (UTC+0:00), AWS Toolkit will fully replace the AWS Resources panel. When toggled, your browser refreshes to update the IDE's interface.

The main reason I use cloud9 is that I can write, edit, and actually have live debugging sessions. Lambda with Cloud9 really accelerates the development of Lambda functions. Losing this feature, honestly makes me feel that we are taking a step back in terms of ease of use.

Things I am struggling with right now are debugging the lambda locally on Cloud9. Usually, Cloud9 would spin up a template.YAML file, but now this is no longer the case.

Looking for help on making this transition, thank you in advance!


r/awslambda • • Jan 15 '21

InfiniCache: A cost-effective memory cache that is built atop ephemeral serverless functions

Thumbnail
github.com
2 Upvotes

r/awslambda • • Jan 05 '21

FFMPEG Code not working in AWS Lambda

2 Upvotes

I followed this article https://aws.amazon.com/blogs/media/processing-user-generated-content-using-aws-lambda-and-ffmpeg/ and deployed the lambda functions and layers and set it up all fine . But I am facing a problem when I try converting the mp4 video into a 720p video , the ffmpeg commands that work in my my ubuntu 20.04 are not working in the lambda and gives me error in the form of 0kb files in the destination folder . Can someone explain why this is happening ? The command that I used was "ffmpeg -i input.mp4 -s 1280x720 -c:a copy output.mp4"


r/awslambda • • Dec 20 '20

Speed-up Lambda functions by using Advanced Vector Extensions

Thumbnail
aws.amazon.com
2 Upvotes

r/awslambda • • Dec 20 '20

How to set up an AWS Lambda and auto deployments with Github Actions

Thumbnail blog.jakoblind.no
2 Upvotes

r/awslambda • • Dec 12 '20

Disable retry

2 Upvotes

Hi all, I'm currently running this script as a Lambda function, sometimes this script has some API timeouts and fails in some way causing Lambda to retry the execution several times. The function is executed via cloudwatch trigger and as far as I would like to avoid the auto-retry execution I wrapped the whole code in a try like suggested here -- is this the "correct" way for handling such a situation? Thanks for feedback


r/awslambda • • Nov 02 '20

[Python] Unable to import file that was added to function via Layers

2 Upvotes

I have a python script (ElectionResults.py) that I uploaded to Lambda as a Layer in a zip file with all of its dependencies. When I try to import this into my function with "import ElectionResults I get the error "Unable to import module 'lambda_function': No module named 'ElectionResults"

EDIT: Never mind, I figured it out. For future reference, make sure that you put your python script inside of a folder called "python" in your zip file


r/awslambda • • Oct 25 '20

Blue Green with CodeDeploy and PreTraffic Hooks

2 Upvotes

I’m liking the idea of a PreTraffic hook to implement a final deployment pre-traffic test and letting CodeDeploy handle that.

The problem I’m having is coming up with something meaningful to test in the PreTraffic hook. I’ve been thinking as a final end to end smoke style test. Maybe even a contract test to validate the JSON being returned. If Unit tests have sufficient code coverage and faith in their tests, it shouldn’t need to be too deep, right?

Does anyone here use these features? Can you share what you test with you traffic hooks?


r/awslambda • • Oct 21 '20

Creating an Authorizer Function that authenticates off the Origin and Referer HTTP Header

2 Upvotes

Is it possible for requests to the API-Gateway to pass the referrer URL to Lambda?

For example, I'd love to let my lambda functions know if a request comes from the domain "good.com" vs. "bad.com".

What is the best way to see the list of data points that I can use to authenticate against in the request header? And how can I properly implement this - I read about authorizers, but not sue if this is the best approach.


r/awslambda • • Oct 14 '20

How to use Lambda resource based policy for granular access to single IAM principal?

2 Upvotes

I have a Lambda function that is running a script that is sensitive in nature, and need to lock it down so that only a specific SSO role can make changes to it. Has anyone accomplished something like this before? General idea behind what I'd like to apply to this resource based policy is this:

{
    "Version": "2012-10-17",
    "Id": "Allow",
    "Statement": [
        {
            "Sid": "RestrictedAccess",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::<account_id>:role/aws-reserved/sso.amazonaws.com/<SSO_Role>"
            },
            "Action": "lambda:*",
            "Resource": "*"
        }
    ]
}

I found this documentation, but in my testing it seems that adding permissions does not have the intended effect of limiting access with an implicit deny based on the explicit allow.

https://docs.aws.amazon.com/lambda/latest/dg/access-control-resource-based.html


r/awslambda • • Oct 05 '20

Unit/Integ test for lambda in Typescript

2 Upvotes

Our team has been using and lambda/nodejs for some time. Here is how we do unit/integration test on the lambdas.

Later I will also showcase how to do integration test on DDB.

https://link.medium.com/QfFpgy7ukab

Thanks.


r/awslambda • • Sep 26 '20

Removing \ characters when returning HTML from Lambda Function

2 Upvotes

I have a lambda function where I render an HTML template and pass it back to API Gateway for it to be rendered when somebody hits our endpoint. What I am finding is that when I return the HTML, all these escape characters are being added.

Below is the full function:

from flask import Flask, render_template  

def lambda_handler(event, context):         
    html_data =''     
    with app.app_context():         
        html_data = render_template('index.html')          
return {         
        "body":html_data
     } 

So do not get lost in all the code, but what is happening is that all these \n and \ characters are appearing all over the HTML file.

Below is the Response:

Response {     "body": "<!DOCTYPE html>\n<html lang=\"en\" dir=\"ltr\">\n  <head>\n    <link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css\" integrity=\"sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm\" crossorigin=\"anonymous\">\n    <script src=\"https://code.jquery.com/jquery-3.2.1.slim.min.js\" integrity=\"sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN\" crossorigin=\"anonymous\"></script>\n    <script src=\"https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js\" integrity=\"sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q\" crossorigin=\"anonymous\"></script>\n    <script src=\"https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js\" integrity=\"sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl\" crossorigin=\"anonymous\"></script>\n\n    <meta charset=\"utf-8\">\n    <title></title>\n  </head>\n  <body>\n    <ul class='nav'>\n      <li class='nav-link'>\n        <a href=\"#\">Home</a>\n      </li>\n      <li class='nav-link'>\n        <a href=\"#\">About</a>\n      </li>\n      <li class='nav-link'>\n        <a href=\"#\">Log Out</a>\n      </li>\n      <li class='nav-link'>\n        <a href=\"#\">Account</a>\n      </li>\n      <li class='nav-link'>\n        <a href=\"#\">Create Post</a>\n      </li>\n      <li class='nav-link'>\n        <a href=\"#\">Log In</a>\n      </li>\n      <li class='nav-link'>\n        <a href=\"#\">Register</a>\n      </li>\n    </ul>\n<div class=\"container\">\n  \n  <div class=\"jumbotron\">\n    <h1>Puppy Company Blog</h1>\n  </div>\n\n</div>\n  </body>\n</html>" } 

I am not sure what is causing this, but I am surely doing something wrong here.

EDIT UPDATE:

I found the following SOF post, which I think might get me on the right track.

https://stackoverflow.com/questions/15297028/how-do-i-escape-closing-in-html-tags-in-json-with-python

EDIT AGAIN:

html_data.replace('\n','') is my hacky way of solving this.


r/awslambda • • Sep 20 '20

Coding inside of the AWS Lambda Console

2 Upvotes

Hi guys - I really like being able to code inside of the AWS Lambda function console. My only issue is that once the file gets too big, it tells me that I can no longer program with their UI.

I was wondering if there were any plugins or something that I could do to avoid this issue.

Why do I like this? I am not an engineer and using the CLI to wrap and upload code to my lambda is honestly quite difficult. I would love it if I could keep programming in their UI.

EDIT: Since this post I found the AWS Cloud9 IDE. Looks very promising!


r/awslambda • • Sep 07 '20

Is this a Django Problem or AWS Problem?

Thumbnail self.djangolearning
2 Upvotes

r/awslambda • • Sep 04 '20

Lambda Updated Time Display Issue

2 Upvotes

Hello community!! In my project, I was working on AWS lambda through the AWS console and I have updated the lambda on that day but on the next day It was showing that you have modified this lambda 5 days ago..

I still can’t understand that why it is showing like this in Latest version.


r/awslambda • • Sep 01 '20

Jinja templates with AWS Lambda

2 Upvotes

I am looking for resources on how to launch html pages with jinja templates using lambda functions.

Basically the overall goal is that I want to pass data to the html page that is rendered from the lambda.

Anybody ever do this?


r/awslambda • • Aug 14 '20

Adding Python Library to AWS layers

2 Upvotes

I have a python package that I need to import to my script AWS Lambda Script:

simple-salesforce

For more information please see: https://pypi.org/project/simple-salesforce/

I need to add this to my AWS Lambda function as a layer to access it.

I follow the following video for doing this:

https://www.youtube.com/watch?v=cz8QjmgfGHc

When I do this I see the following error:

Importing the numpy c-extensions failed.

The major difference between myself and this video is that when I type in python --version, I see the following:

Python 3.6.10 :: Anaconda, Inc.

How can I update to use the latest version of python and what is this Anaconda attached to it? I genuinely think my errors lie here.

Overall, my goal is to get the simple-salesforce package into my lambda function.


r/awslambda • • Aug 14 '20

Hands-on exercise to use Lambda Function with Systems Manager

Thumbnail
aws-dojo.com
2 Upvotes