aws-lambda

Why is this JSON property being logged as undefined?

非 Y 不嫁゛ 提交于 2020-05-30 08:01:18
问题 I have a nodejs lambda that has an SQS queue as an event, which is subscribed to an SNS topic. The lambda looks like this: 'use strict'; import { Handler } from 'aws-lambda'; const myLambda: Handler = async (event: any = {}) => { let incomingMessage = JSON.stringify(event.Records[0].body); console.log('Received event:', incomingMessage); # log1 console.log('parsed event',JSON.parse(incomingMessage)); # log2 var type = JSON.parse(JSON.stringify(incomingMessage)).Type; console.log('Message

Why is this JSON property being logged as undefined?

妖精的绣舞 提交于 2020-05-30 08:00:24
问题 I have a nodejs lambda that has an SQS queue as an event, which is subscribed to an SNS topic. The lambda looks like this: 'use strict'; import { Handler } from 'aws-lambda'; const myLambda: Handler = async (event: any = {}) => { let incomingMessage = JSON.stringify(event.Records[0].body); console.log('Received event:', incomingMessage); # log1 console.log('parsed event',JSON.parse(incomingMessage)); # log2 var type = JSON.parse(JSON.stringify(incomingMessage)).Type; console.log('Message

Can you send a message to a websocket client from a non-websocket lambda?

亡梦爱人 提交于 2020-05-30 07:36:06
问题 I have a nodejs websocket AWS lambda endpoint (Api Gateway) set up and it connects and can echo messages back. During initial connection, I save the endpoint and connection_id to a database. That gets saved just fine. If I open a browser client, and connect to the websocket endpoint, I can connect successfully, and send a message from the browser successfully - I have code to echo the message back, and it works. Now, in another nodejs lambda, one that provides a REST endpoint, I have code

Can you send a message to a websocket client from a non-websocket lambda?

佐手、 提交于 2020-05-30 07:35:12
问题 I have a nodejs websocket AWS lambda endpoint (Api Gateway) set up and it connects and can echo messages back. During initial connection, I save the endpoint and connection_id to a database. That gets saved just fine. If I open a browser client, and connect to the websocket endpoint, I can connect successfully, and send a message from the browser successfully - I have code to echo the message back, and it works. Now, in another nodejs lambda, one that provides a REST endpoint, I have code

Why can my code run in a standard Node.js file, but not in a AWS Lambda Function?

寵の児 提交于 2020-05-29 09:08:26
问题 What I'm trying to do is create a lambda function where the function calls two commands on an ec2 instance. When I had trouble running this code in a lambda function, I removed the code from the exports.handler() method and ran the code in a standalone node.js file in the same ec2 instance and I was able to get the code to work. The command I ran was 'node app.js'. exports.handler = async (event) => { const AWS = require('aws-sdk') AWS.config.update({region:'us-east-1'}); var ssm = new AWS

Aws Lambda response error

。_饼干妹妹 提交于 2020-05-29 08:24:51
问题 I am running aws lambda which will fetch data from maria DB and return the fetched rows as a JSON object. A total number of item in JSON array is 64K. I am getting this error: { "error": "body size is too long" } Is there a way I can send all 64K rows by making any configuration change to lambda? 回答1: You cannot send the 64K rows (Which goes beyond 6MB body payload size limit) making configuration changes to Lambda. Few alternative options are. Query the data and build a JSON file with all

cannot create aws lamda function due to some cryptic error message

て烟熏妆下的殇ゞ 提交于 2020-05-26 10:16:17
问题 I am trying to create an aws lambda function but when I click deploy I get this error message: Correct the errors below and try again. Your function's execution role must be assumable by the edgelambda.amazonaws.com service principal. I have absolutely no idea what this means. 回答1: From the Lambda@Edge IAM Role documenation: You must create an IAM role that can be assumed by the service principals lambda.amazonaws.com and edgelambda.amazonaws.com. This role is assumed by the service

AWS Lambda w/ SQS trigger, SQS Lambda Destinations, never adds to destination queue

你离开我真会死。 提交于 2020-05-25 08:50:13
问题 I have a simple lambda function that is triggered from a SQS queue and I'm using the new Lambda Destinations functionality. It is set up to trigger from QUEUE_A , do some modification of the payload body, then send it to QUEUE_B on success , or QUEUE_ERRORS on failure . QUEUE_B and QUEUE_ERRORS are set up as Destinations on the lambda function. When I trigger the lambda from the CLI, I get a record on QUEUE_B with a good record, and on QUEUE_ERRORS on a bad record. So, it seems to be working.

how to call rest api inside aws lambda function using nodejs

感情迁移 提交于 2020-05-25 05:12:13
问题 i have created aws lambda function. i want to use rest api calls inside my lambda function. Is there any reference how to connect it to rest api using nodejs 回答1: If you want to call rest api inside lambda function, you can use request package: install request package via npm: https://www.npmjs.com/package/request Then inside lambda function try this to call rest api: var req = require('request'); const params = { url: 'API_REST_URL', headers: { 'Content-Type': 'application/json' }, json:

AWS-amplify Including the cognito Authorization header in the request

这一生的挚爱 提交于 2020-05-25 04:54:21
问题 I have create an AWS mobile hub project including the Cognito and Cloud logic. In my API gateway, I set the Cognito user pool for the Authorizers. I use React native as my client side app. How can I add the Authorization header to my API request. const request = { body: { attr: value } }; API.post(apiName, path, request) .then(response => { // Add your code here console.log(response); }) .catch(error => { console.log(error); }); }; 回答1: By default, the API module of aws-amplify will attempt