小编squ*_*ave的帖子

在 NodeJS 中获取来自 AWS SQS 的所有消息

我有以下函数从 aws SQS 获取消息,问题是我一次获取一条消息,并且希望获取所有消息,因为我需要检查每条消息的 ID:

function getSQSMessages() {

    const params = {
        QueueUrl: 'some url',
    };

    sqs.receiveMessage(params, (err, data) => {
        if(err) {
            console.log(err, err.stack)
            return(err);
        }
        return data.Messages;
    });

};

function sendMessagesBack() {

    return new Promise((resolve, reject) => {
        if(Array.isArray(getSQSMessages())) {
            resolve(getSQSMessages());
        } else {
            reject(getSQSMessages());
        };
    });

};
Run Code Online (Sandbox Code Playgroud)

函数sendMessagesBack()用于另一个 async/await 函数。我不确定如何获取所有消息,因为我正在寻找如何获取它们,人们提到了循环,但我不知道如何在我的情况下实现它。我假设我必须将 sqs.receiveMessage()放入循环中,但随后我对需要检查什么以及何时停止循环以便获取每条消息的 ID 感到困惑?

如果有人有任何提示,请分享。谢谢。

amazon-sqs amazon-web-services node.js

5
推荐指数
2
解决办法
8956
查看次数

参数中缺少必需的键“Bucket”

我正在尝试将一个简单的 lambda 函数部署到 aws,但我收到错误Missing required key 'Bucket' in params。我创建的用户拥有完整的 Lambda、S3、Cloudformation 和 Cloudwatch 访问权限。

JS

'使用严格';

module.exports.hello = (event, context, callback) => {
  const response = {
    statusCode: 200,
    body: JSON.stringify({
      message: 'Go Serverless v1.0! Your function executed successfully!',
      input: event,
    }),
  };

  callback(null, response);

  // Use this code if you don't use the http event with the LAMBDA-PROXY integration
  // callback(null, { message: 'Go Serverless v1.0! Your function executed successfully!', event });
};
Run Code Online (Sandbox Code Playgroud)

YAML

service: lambda-demo

provider:
  name: …
Run Code Online (Sandbox Code Playgroud)

amazon-s3 aws-lambda serverless

4
推荐指数
2
解决办法
1万
查看次数

无法在Node.js中导入模块``处理程序''AWS Lambda函数

我不断收到此错误,但我不知道是什么原因引起的。

我有一个根据条件发布到另一个API的API,但是在包装API中遇到此错误。

这是代码...

handler.js

'use strict';
const axios = require('axios');

module.exports.thumbnailWrapperAPI = (event, context, callback) => {


  const incomingData = JSON.parse(event.body);
  if(incomingData.source.includes('png') || incomingData.source.includes('jpg')){
    const newLocal = 'some endpoint...';
    // call image resizing API...
    axios.post(newLocal,{
      source: incomingData.source,
      target: incomingData.target,
      width: incomingData.width
    })
    .then(response => callback(null,response))
    .catch(error => callback(error))

  } else if(incomingData.source.includes('html')) {
    // handle HTML
  } else {
    //...
  };
};
Run Code Online (Sandbox Code Playgroud)

serverless.yaml

service: thumbnailWrapperAPI 
provider:
  name: aws
  runtime: nodejs8.10
  region: eu-west-1

functions:
  thumbnailWrapperAPI:
    handler: handler.thumbnailWrapperAPI
    events:
      - http:
          path: generatethumbnail/ …
Run Code Online (Sandbox Code Playgroud)

node.js aws-lambda serverless-framework aws-serverless

4
推荐指数
2
解决办法
4461
查看次数

如何从无服务器 cli 设置 Cloudformation 完全访问权限

我可以通过编程访问 aws 帐户,当我尝试部署基本功能时,我得到:

用户:arn:aws:iam::xxxx:user/myname 无权对资源执行:cloudformation:DescribeStacks:arn:aws:cloudformation:eu-west-1:xxxxxx:stack/hello-world-dev/*

我检查了我的密钥,它们是正确的,我假设我的用户没有 cloudformation 访问权限。

我的问题是,是否可以在 yaml 文件中设置我的用户的权限?例如cloudformation完全访问、lambda完全访问等。

您可以在下面找到我的 functiona 和 yaml 文件:

处理程序.js

module.exports.helloWorld = (event, context, callback) => {
  const response = {
    statusCode: 200,
    headers: {
      'Access-Control-Allow-Origin': '*', // Required for CORS support to work
    },
    body: JSON.stringify({
      message: 'Go Serverless v1.0! Your function executed successfully!',
      input: event,
    }),
  };

  callback(null, response);
};
Run Code Online (Sandbox Code Playgroud)

无服务器.yaml

service: hello-world

provider:
  name: aws
  runtime: nodejs8.10
  region: eu-west-1
  # iamRoleStatements:
  #   - Effect: "Allow"
  #     Action:
  #      - cloudformation: …
Run Code Online (Sandbox Code Playgroud)

node.js aws-cloudformation aws-lambda serverless aws-serverless

4
推荐指数
1
解决办法
3733
查看次数

如何在Framework7中导航到页面

我只是从Framework7开始,我想单击一个段落时导航到另一页。我尝试了几件事,并在过去一个小时内用Google搜索,但是没有运气。

这是我在my-app.js中的代码:

var $$ = Dom7;

var app = new Framework7({
    // App root element
    root: '#app',
    // App Name
    name: 'My App',
    // App id
    id: 'com.myapp.test',
    // Enable swipe panel
    panel: {
      swipe: 'left',
    },
    view : {
        stackPages: true
    },
    // Add default routes
    routes: [
      {
        name: 'about',
        path: '/about/',
        url: 'about.html',
      },
      {
        name: 'index',
        path: '/index/',
        url: 'index.html'
      },
      {
        name: 'preview',
        path: '/preview/',
        url: './preview.html'
      },
    ],
    // ... other parameters …
Run Code Online (Sandbox Code Playgroud)

javascript routing html-framework-7

3
推荐指数
1
解决办法
3091
查看次数

React Native - undefined不是对象(评估'RNGestureHandlerModule.state')

我收到这个错误,它让我疯了,我甚至无法在React Native上启动一个简单的应用程序.我正在使用最基本的示例,一个新项目仍然会抛出此错误.我使用react-navigation v3xx 有人请帮助,因为我失去了理智,谢谢.这是我的代码:

import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View, Button, TouchableHighlight} from 'react-native';
import { createAppContainer, createStackNavigator, StackActions, NavigationActions } from 'react-navigation'; // Version can be specified in package.json


class Home extends React.Component {
  static navigationOptions = {
    title: "Home",
  }
  render() {
    return (
      <View style={styles.container}>
        <Text>Home Page</Text>
        <Button onPress={() => this.props.navigation.navigate('About')} title="All about me" />
      </View>
    );
  }
}

class AboutMeMe extends React.Component {
  static navigationOptions = {
    title: "All Me",
  } …
Run Code Online (Sandbox Code Playgroud)

react-native react-native-ios react-native-navigation

2
推荐指数
1
解决办法
2889
查看次数

从另一个数组返回带有阶乘数的数组

此函数将接收一个正整数数组,它应返回一个新数组,其中包含每个数字的阶乘.

到目前为止,我想出了这个,但它不起作用,我不知道问题出在哪里,有什么想法吗?

function getFactorials (nums) {
  let arr = [];
  for(let i = 0; i < nums.length; i++) {
    if(nums[i] <= 1) {
      return 1;
     } else {
      arr.push(nums[i] * getFactorials(nums[i] - 1));
     }
   }
  return arr;
 }
Run Code Online (Sandbox Code Playgroud)

javascript arrays recursion

0
推荐指数
1
解决办法
876
查看次数