Questions tagged with AWS Lambda

Content language: English

Sort by most recent

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

Hi, I have simple lambda code: ``` func handleLambdaEvent(ctxOrg context.Context, request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) { orgDL, _ := ctxOrg.Deadline() fmt.Println(orgDL) ``` when its deployed to aws and called ( from API Gateway ) I see in logs current timestamp + X seconds, but when I run this locally and use awslambdarpc to call it I see: > 1970-01-01 00:00:00 +0000 UTC which causes some problems in other parts of this lambda. Is it possible somehow, using awslambdarpc or maybe some config ( just for local ) to define this deadline value ?
2
answers
0
votes
12
views
Baku
asked 11 days ago
How to get the "RuleResults" generated by a glue studio job that have some dataquality rules, in the dataQuality Tab of the job i can manually download the results to a file when appears the "RuleResults". i have one step function where calls that job, i would like to know the output of that file(where was generated and the key in s3, too) to evaluate in a next step(i.e lambda function) which rules were'nt passed and which ones yes. tkx
1
answers
0
votes
20
views
Willi5
asked 11 days ago
Hi there, I'm doing this tutorial: https://docs.aws.amazon.com/step-functions/latest/dg/tutorial-get-started-create-first-sm.html **There I need to create a Lambda Function in Node.js 16.x, this code has been provided:** export const handler = async function(event, context) { const credLimit = Math.floor(Math.random() * 10000); return (credLimit); }; **When I test the code I get the following result though:** { "errorType": "Runtime.UserCodeSyntaxError", "errorMessage": "SyntaxError: Unexpected token 'export'", "trace": [ "Runtime.UserCodeSyntaxError: SyntaxError: Unexpected token 'export'", " at _loadUserApp (file:///var/runtime/index.mjs:993:17)", " at async Object.UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1031:21)", " at async start (file:///var/runtime/index.mjs:1194:23)", " at async file:///var/runtime/index.mjs:1200:1" ] } This is the first function in the state machine this tutorial is about. This error appears also when I execture the state machine of course. I am quite a newbie and don't know how to proceed...can someone help me please? Thanks in advance! Best Moe
2
answers
0
votes
28
views
Moe
asked 11 days ago
Hello All, Cognito/Amplify Team, I am implementing passwordless SMS auth. Flow is: signIn -> error (userNotFound) -> signUp -> signIn -> OTP sent to mobile -> OTP entered by user -> confirmSignIn -> success and user is logged in. This flow works and user is able to successfully sign in. But verification of phone_number should better happen in PostAuthentication (after user is signed in after entering and successfully checking OTP) and not before that in PreSignUp. I have following lambdas: PreSignUp, DefineAuthChallenge, CreateAuthChallenge, VerifyAuthChallengeResponse, PostAuthentication. Things have run fine. Want to change one thing for good: Auto verify phone number in Post Authentication instead of PreSignUp lambda. How to do that? I thought following can do it in PostAuthentication lambda: ``` event.response.phone_number_verified = "true" ``` it did not. I also tried with setting: ``` event.request.userAttributes.phone_number_verified = "true" ``` it also did not. In PreSignUp, following did work fine: ``` event.response.autoVerifyPhone = true; ``` ---------------------------------------------- PostAuthentication lambda (custom.js): ``` exports.handler = async (event, context) => { console.log('Received EVENT', JSON.stringify(event, null, 2)); if (event.request.userAttributes.hasOwnProperty("email") && event.request.userAttributes.email_verified != "true") { event.request.userAttributes.email_verified = "true" event.response.email_verified = "true"; } if (event.request.userAttributes.hasOwnProperty("phone_number") && event.request.userAttributes.phone_number_verified != "true") { event.request.userAttributes.phone_number_verified = "true"; event.response.phone_number_verified = "true"; } console.log('Returning event', JSON.stringify(event, null, 2)) return event; }; ``` ---------------------------------------------- PreSignUp (custom.js): ``` "use strict"; exports.handler = async (event) => { console.log('Received EVENT', JSON.stringify(event, null, 2)); event.response.autoConfirmUser = true; /* if (event.request.userAttributes.hasOwnProperty("email")) { event.response.autoVerifyEmail = true; } if (event.request.userAttributes.hasOwnProperty("phone_number")) { event.response.autoVerifyPhone = true; } */ console.log('Returning EVENT', JSON.stringify(event, null, 2)); return event; ``` ---------------------------------------------- But when I check user in Cognito, it still shows as NotVerified. [1] which is in TS but also suggest to set: event.request.userAttributes.email_verified = "true" [2] does not suggest how to auto verify phone_number in PostAuthentication lambda. [3] does suggest how to auto verify phone_number in PreSignUp. [1] https://github.com/aws-samples/amazon-cognito-passwordless-email-auth/blob/master/cognito/lambda-triggers/post-authentication/post-authentication.ts [2] https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-post-authentication.html [3] https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-pre-sign-up.html ---------------------------------------------- Can you help resolve this. How/what to set in PostAuthentication to auto verification of phone number? Thanks in advance.
2
answers
0
votes
17
views
Raj
asked 11 days ago
I checked the rule itself and the event scheduler. Just as a test, I had it running every five minutes. However, when I checked on the lambda's cloudwatch log group, there was nothing. Rule state is enabled. The trigger is there in the lambda. In the cloudwatch metrics, there's actually data, but nothing is logged. It also reports a success so I don't think it's a permissions issue. Also, when I tried to add the rule's ARN to the Configuration>Permissions tab, it reports an error because the ARN contains a forward slash and it allows backward slashes. I'm using the code from this guide: https://aws.amazon.com/blogs/security/how-to-monitor-expirations-of-imported-certificates-in-aws-certificate-manager-acm/ so I don't think it's the lambda itself. I also just put a print statement in the lambda_handler just to see if anything outputs. Nothing does.
1
answers
0
votes
17
views
asked 11 days ago
I want to write an AWS Lambda function that is able to respond to various types of event types: API Gateway, Kinesis, S3, etc. The API/SDK I need to work with is Java. I'd like to create a general-purpose handler, but it appears that each service has its own event type and does not derive from some common parent event type. Is there a pattern or a best practice for creating an AWS Lambda function that can be used with a variety of event types? Or do I need to create a custom handler for each event type?
1
answers
0
votes
18
views
Brian
asked 12 days ago
Hi AWS, Is this workflow architecture possible: RDS (PostgreSQL) --------------------> Amazon MQ Broker --------------> Lambda Function -----------------------> S3 Bucket (Data is stored for customers) The database can be in DynamoDB as well. Amazon MQ is used as an event-source for the lambda function and the lambda is sending the request to API Gateway and getting the JSON response and further sending it to S3 to be stored as output. Please suggest
2
answers
0
votes
39
views
profile picture
asked 12 days ago
I was following this document, https://docs.aws.amazon.com/iot/latest/developerguide/connect-iot-lorawan-network-analyzer-request-sample.html Able to generate the signature but when trying to execute any CloudWatch metric api I am getting 200 as response code and null response even though the metric and dashboard data is there. Is there any other way to get the metric data from cloudwatch or any other more detailed document which can be referred for API execution?
1
answers
0
votes
22
views
asked 12 days ago
I have developed some code on my local PC from which I created a lambda function which contains environment variables and a layer with my libraries. When I run the code it works. I have decided that I really should be developing this code using Cloud9 so I can debug it when I make more changes. I have been able to access my code OK via the AWS explorer but when I attempt to run it I notice that it falls over because it cannot locate a library. I realise it is not accessing the layer I uploaded, the error message is "ModuleNotFoundError: No module named 'tweepy'". So how do I access the existing Lambda layer I created, but this time in Cloud9?
1
answers
0
votes
29
views
asked 13 days ago
I am trying to invoke a lambda to store data in a Dynamodb table. In my own AWS account, it works, but not in the company AWS account I'm working at. Cloudwatch does not show any errors. The timeout occurs at "await dynamodb.describeTable(describeParams).promise();". ![Calling the invoke API action failed with this message: Network Failure timeout](/media/postImages/original/IMvwBjv-QCSNWBn1sD7PSBiQ) My code is as follows: ``` const AWS = require('aws-sdk'); const docClient = new AWS.DynamoDB.DocumentClient(); const dynamodb = new AWS.DynamoDB(); exports.handler = async (event) => { const valueTostore = event.body || 'default_value'; const params = { TableName: 'my-values', Item: { id: new Date().toISOString(), SessionConfig: valueTostore } }; try { const describeParams = { TableName: 'my-values' }; await dynamodb.describeTable(describeParams).promise(); } catch (error) { const response = { statusCode: 500, body: JSON.stringify({ message: 'Error while accessing table' }) }; return response; } try { await docClient.put(params).promise(); } catch (error) { const response = { statusCode: 500, body: JSON.stringify({ message: 'Error while storing value' }) }; return response; } const response = { statusCode: 200, body: JSON.stringify({ message: 'Value stored successfully' }) }; return response; }; ```
3
answers
0
votes
31
views
combii
asked 14 days ago
Hello I'm trying to run a SAM instance locally containing an API Gateway and a Lambda written in python. My goal is to POST images to my API so that I can upload them to an S3 bucket where they can be publicly served. If I do HTTP operations using JSON everything works fine, but when I try to POST a binary type like 'image/jpeg' I get the following error: ``` 2023-03-18 09:06:27 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit) UnicodeDecodeError while processing HTTP request: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte 2023-03-18 09:06:34 127.0.0.1 - - [18/Mar/2023 09:06:34] "POST /media HTTP/1.1" 502 - ``` I've tried adding BinaryMediaTypes to my template.yaml and create a fully defined CloudFormation but I still get this error. Here's my code: https://github.com/caelumvox/blog-api Would anyone know how to get this working locally? Thank you
0
answers
0
votes
16
views
asked 14 days ago
I am playing with this tutorial, https://aws.amazon.com/ko/blogs/mobile/new-real-time-multi-group-app-with-aws-amplify-graphql-build-a-twitter-community-clone/ I wanted to add the delete function for cognito group. But I could not. This is What I did. 1. amplify/backend/api/twittercommunity/schema.graphql type Tweet @model @auth(rules: [ { allow: owner, operations: [create, delete] }, { allow: groups, groupsField: "community", ***operations: [read]*** } ]) { content: String! community: String! } I add "delete" **operations: [read, delete]** 2. amplify/backend/function/AdminQueries/src app.js file: added this const { addUserToGroup, removeUserFromGroup, addAndJoinGroup, listGroups, **deleteGroup,** listGroupsForUser, listUsersInGroup, } = require('./cognitoActions'); app.get('/deleteGroup', async (req, res, next) => { if (!req.body.groupname) { const err = new Error('Groupname is required'); err.statusCode = 400; return next(err); } try { const username = req.apiGateway.event.requestContext.authorizer.claims.username const response = await deleteGroup(username, req.body.groupname); res.status(200).json(response); } catch (err) { next(err); } }); and in the cogintoActions.js async function deleteGroup(username, groupname) { const params = { GroupName: groupname, UserPoolId: userPoolId }; console.log('delete group', params) console.log(`Attempting to remove ${groupname} from ${userPoolId}`); cognitoIdentityServiceProvider.deleteGroup(params, function (err, data) { if (err) console.log(err, err.stack); else console.log(data); }); module.exports = { addUserToGroup, removeUserFromGroup, addAndJoinGroup, listGroups, listGroupsForUser, listUsersInGroup, **deleteGroup** }; and the amplify/backend/function/AdminQueriesXYZ/AdminQueriesXYZ-cloudformation-template.json at the “PolicyDocument” section, added it. **"cognito-idp:DeleteGroup",** and the src/utils.js export async function deleteGroup(groupName) { console.log('deleteGroup: ', groupName) await API.post( API_NAME, '/deleteGroup', { body: { groupname: groupName }, headers: { 'Content-Type': 'application/json', Authorization: `${(await Auth.currentSession()).getAccessToken().getJwtToken()}` } }); await invalidateRefreshToken(); } and the delete button in the GroupPanels.js Only group-creator can delete the group, and should enter right name of the groupname to delete. async function handleDeleteGroupClick() { await deleteGroup(window.prompt('Group Name?')) refreshGroups() } <Button size="small" variation="link" onClick={() => handleDeleteGroupClick()} isDisabled={user.attributes.sub !== owner}> delete </Button> However, It gave an 404 error. I do not know how to fix it any more. please help me out.
0
answers
0
votes
15
views
asked 14 days ago