Questions tagged with Serverless

Content language: English

Sort by most recent

Browse through the questions and answers listed below or filter and sort to narrow down your results.

How to handle Typescript lambdas using modules embedded in a CDK project

I have a question that's kind of a CloudFormation question but I guess is really a CDK question. My project layout looks like this: ``` work\. ├───cdk.out ├───bin ├───lib ├───node_modules ├───src │ ├───common │ ├───ep │ ├───sites │ └───static ├───package.json ├───tsconfig.json └───test ``` The directories ep, sites, and static are all individual lambdas; the constructor script calls them out like this: ``` entry: path.join(__dirname, "../src/sites/sites.ts"), ``` so that works great. In the package.json I am very careful about what goes into 'dependencies' vs. 'devDependencies' to avoid conflicts and bloat. It occurred to me, though, that some day I might end up with other problems, like conflicts, so I was searching around to see if I can give each individual lambda (ep, sites, static) their own package.json and maybe even tsconfig.json. I found a few things saying it works, but a few others saying it won't. `yarn build` only shows it running tsc once. I think the answer to this is to use [modules](https://javascript.plainenglish.io/how-to-create-multi-module-nodejs-applications-9aff2d73dc17) but because of the way you define an [entry point](https://docs.aws.amazon.com/cdk/api/v1/docs/@aws-cdk_aws-lambda-nodejs.NodejsFunction.html) (as a path to a single file) I don't get the idea this would work. I'm not sure how to make the lambdas within the CDK project more independent. Do I need to build them into their own, separate projects (outside of the CDK project), bundle them (say with webpack), then have the CDK project reference the build outputs for each? That sounds a little messier, and I like having the entire stack (lambdas and all) in one place. Is there a more self-contained way to do this? Generally speaking, my lambdas are classes. This means that each one has an entry point defined that's just a regular function. If I knew how modules work, could I make each lambda be a module, that's its own class, and have 'entry' point to just a plain typescript function that's part of the CDK project that does something like: ``` import { SpecialHandler } from ../xyz; export async function handleSpecialRequest(request: APIGatewayProxyEventV2): Promise<APIGatewayProxyResultV2> { return new SpecialHandler.handleRequest(request); } ```
1
answers
0
votes
14
views
wz2b
asked 20 days ago

AWS Lambda: [Errno 13] Permission denied: '/tmp/ffmpeg'

Hi, I am trying to use moviepy in my serverless application on AWS Lambda. Since ffmpeg is used inside moviepy I am facing errors related to ffmpeg while executing the function. 1. I have created a docker file and deployed the container image for the function. I am using M1 (arm64)- MacOS as the platform 2. I have set the exec variable before importing moviepy, as shown below ``` os.environ["IMAGEIO_FFMPEG_EXE"] = "/tmp/ffmpeg" ``` 3. I have uploaded the ffmpeg executable to S3 and am downloading to /tmp/ffmpeg in the lambda function handler. 4. After downloading I am changing the permissions of "/tmp/ffmpeg" to 755. 5. Still I am getting error as shown below: ``` errorMessage": "[Errno 13] Permission denied: '/tmp/ffmpeg'", "errorType": "PermissionError", "stackTrace": [ " File \"/var/task/app.py\", line 65, in handler\n scaledDownFilename = scaleDown(event[\"filename\"])\n", " File \"/var/task/app.py\", line 40, in scaleDown\n clip = mp.VideoFileClip(filename + \".mp4\")\n", " File \"/var/task/moviepy/video/io/VideoFileClip.py\", line 88, in __init__\n self.reader = FFMPEG_VideoReader(filename, pix_fmt=pix_fmt,\n", " File \"/var/task/moviepy/video/io/ffmpeg_reader.py\", line 35, in __init__\n infos = ffmpeg_parse_infos(filename, print_infos, check_duration,\n", " File \"/var/task/moviepy/video/io/ffmpeg_reader.py\", line 257, in ffmpeg_parse_infos\n proc = sp.Popen(cmd, **popen_params)\n", " File \"/var/lang/lib/python3.8/subprocess.py\", line 858, in __init__\n self._execute_child(args, executable, preexec_fn, close_fds,\n", " File \"/var/lang/lib/python3.8/subprocess.py\", line 1704, in _execute_child\n raise child_exception_type(errno_num, err_msg, err_filename)\n" ] } ``` **Does anyone know how to resolve this ?**
1
answers
0
votes
72
views
asked 21 days ago

Race Condition Error in AWS-Parameters-and-Secrets-Lambda-Extension

Hey, we tried to use the AWS-Parameters-and-Secrets-Lambda-Extension to get some parameters within our Lambda Function. Unfortunately the code of the layer throws an error. As far I can tell from the outside it looks like a race condition error. It mostly happens after the function got deployed and runs for the first time, or when it comes back from a cold start. I do not know if this is the right place to report it, but here are some details. Let me know if there is a Repo where I can create an Issue. Environment: Lambda, `arm64`, `Node.js 16.x` Layer: `arn:aws:lambda:eu-west-1:015030872274:layer:AWS-Parameters-and-Secrets-Lambda-Extension-Arm64:2` Error: ``` fatal error: concurrent map read and map write goroutine 8 [running]: golang.a2z.com/GoAmzn-SSMParameterStoreLambdaExtension/cache.(*Cache).Add(0x40001a6140, {0x31f0e0?, 0x400001f990}, {0x36e2c0?, 0x4000484900}, 0x6a3780?) /local/p4clients/pkgbuild-6j8da/workspace/src/GoAmzn-SSMParameterStoreLambdaExtension/cache/cache.go:69 +0x114 golang.a2z.com/GoAmzn-SSMParameterStoreLambdaExtension/parameters.(*Retriever).Get(0x40001b4280, 0x40001e1b90) /local/p4clients/pkgbuild-6j8da/workspace/src/GoAmzn-SSMParameterStoreLambdaExtension/parameters/retriever.go:107 +0x84c ... /opt/brazil-pkg-cache/packages/GoLang/GoLang-1.x.89619.0/AL2_x86_64/DEV.STD.PTHREAD/build/lib/src/net/http/transport.go:1752 +0x1234 ``` The stack trace is very long so i skipped a lot in between `...` if one need it please ask.
0
answers
0
votes
15
views
asked 22 days ago

Cognito does not call CreateAuthChallenge trigger

I'd like to configure custom authentication flow with AWS Cognito so I used [this](https://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-user-pools-authentication-flow.html#Custom-authentication-flow-and-challenges) and [this](https://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-user-pools-authentication-flow.html#amazon-cognito-user-pools-custom-authentication-flow) instructions to do this. Previously, I configured password authentication with a possibility to specify a user email or phone number as a username with sending confirmation codes via custom sender triggers and it worked fine. But then after adding custom authentication triggers I realized, that there is no `CreateAuthChallenge` call - only `DefineAuthChallenge`. So what I have now: 1. I call `InitiateAuth` with the following body: ``` { "AuthFlow": "CUSTOM_AUTH", "ClientId": "{{client_id}}", "AuthParameters": { "USERNAME": "{{username}}", "SECRET_HASH": "{{secret_hash}}" } } ``` 2. The response of this call is: ``` { "ChallengeName": "MY_AUTH", "ChallengeParameters": { "USERNAME": "59edb46e-...-8f74a7084057" }, "Session": "AYABeC...jA_TyA" } ``` 3. At the same time in the logs I see only one lambda call with the following event as an argument: ``` { "version": "1", "region": "me-south-1", "userPoolId": "me-south-1_...", "userName": "59edb46e-...-8f74a7084057", "callerContext": { "awsSdkVersion": "aws-sdk-unknown-unknown", "clientId": "44v...bp" }, "triggerSource": "DefineAuthChallenge_Authentication", "request": { "userAttributes": { "sub": "59edb46e-...-8f74a7084057", "cognito:email_alias": "devops@example.com", "cognito:user_status": "CONFIRMED", "email_verified": "true", "email": "devops@example.com" }, "session": [], "userNotFound": false }, "response": { "challengeName": null, "issueTokens": null, "failAuthentication": null } } ``` According to the [docs](https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-create-auth-challenge.html) right after this event I should see the event for `CreateAuthChallenge` trigger but I see nothing. The trigger that is called for those events has the following code: ``` import json import requests def handler(event, context): print('### EVENT ###') print(json.dumps(event)) source = event.get("triggerSource", "unknown") sessions = event.get("request", {}).get("session", []) if source == "DefineAuthChallenge_Authentication": event["response"]["issueTokens"] = False event["response"]["failAuthentication"] = True if len(sessions) == 0: event["response"]["issueTokens"] = False event["response"]["challengeName"] = "MY_AUTH" event["response"]["failAuthentication"] = False print(json.dumps(event)) return event if len(sessions) == 1 and sessions[0].get("challengeName", "") == "CUSTOM_CHALLENGE" and sessions[0].get("challengeResult", False) and sessions[0].get("challengeMetadata", "") == "MY_AUTH": event["response"]["issueTokens"] = True event["response"]["failAuthentication"] = False print(json.dumps(event)) return event print("unexpected sessions sequence: ", sessions) return event if source == "VerifyAuthChallengeResponse_Authentication": event["response"]["answerCorrect"] = False return event print("unexpected triggerSource: ", source) return event ``` Please advise what I can do to make Cognito calling `CreateAuthChallenge` trigger to pass public and private data according to the docs. Thanks!
1
answers
0
votes
16
views
asked 23 days ago