我有以下函数用于从我的代码中调用Lambda函数.
但是,当我尝试在Lambda函数中使用它时,我收到以下错误:
AWS lambda undefined 0.27s 3 retries] invoke({ FunctionName: 'my-function-name',
InvocationType: 'RequestResponse',
LogType: 'Tail',
Payload: <Buffer > })
Run Code Online (Sandbox Code Playgroud)
如何在Lambda函数中调用Lambda函数?
我的功能:
'use strict';
var AWS = require("aws-sdk");
var lambda = new AWS.Lambda({
apiVersion: '2015-03-31',
endpoint: 'https://lambda.' + process.env.DYNAMODB_REGION + '.amazonaws.com',
logger: console
});
var lambdaHandler = {};
// @var payload - type:string
// @var functionName - type:string
lambdaHandler.invokeFunction = function (payload, functionName, callback) {
var params = {
FunctionName: functionName, /* required */
InvocationType: "RequestResponse",
LogType: "Tail",
Payload: new Buffer(payload, …
Run Code Online (Sandbox Code Playgroud) 我正在尝试AWS S3
使用nodejs 从存储桶中获取图像,将其大小调整为4种不同的大小,然后将其保存回同一个存储桶,但保存到一个文件夹中,该文件夹又包含4个文件夹,每个文件夹用于新的大小.
当我运行该函数时,我收到以下错误:
Unable to resize devimageresize/diavelBlack.jpg and upload to / due to an error: Error: Stream yields empty buffer
Run Code Online (Sandbox Code Playgroud)
我对nodejs比较新,我不确定我是否正确编写代码.导致此错误的原因是什么?
这是我的代码:
// dependencies
var async = require('async');
var AWS = require('aws-sdk');
var gm = require('gm');
var util = require('util');
// get reference to S3 client
var s3 = new AWS.S3();
exports.handler = function(event, context) {
// Read options from the event.
console.log("Reading options from event:\n", util.inspect(event, {depth: 5}));
var srcBucket = event.Records[0].s3.bucket.name;
var srcKey = event.Records[0].s3.object.key; …
Run Code Online (Sandbox Code Playgroud) 在设计 a 时REST API
,unique request identifier
在执行 http 请求时添加 a 的最佳做法是什么?
我通常会将它添加到标题中x-request-id
,但是今天听到有人提到将它添加到 url 中作为查询字符串!
同样在做了一些研究之后,似乎有些人将它添加到响应正文中并将其作为有效负载的一部分发送!
在这三个中哪个是最好的应用程序,unique request identifier
为什么?每种方法可能的优缺点是什么?
在mac
works 和 on 上运行以下 docker 命令linux
,runningubuntu
找不到aws cli
凭据。它返回以下消息:Unable to locate credentials
Completed 1 part(s) with ... file(s) remaining
该命令运行映像并挂载数据卷,然后从 s3 存储桶复制文件,并在 docker 容器中启动 bash shell。
sudo docker run -it --rm -v ~/.aws:/root/.aws username/docker-image sh -c 'aws s3 cp s3://bucketname/filename.tar.gz /home/emailer && cd /home/emailer && tar zxvf filename.tar.gz && /bin/bash'
我在这里缺少什么?
这是我的Dockerfile
:
FROM ubuntu:latest
#install node and npm
RUN apt-get update && \
apt-get -y install curl && \
curl -sL …
Run Code Online (Sandbox Code Playgroud) 由于某种原因proxquire
找不到我的模块index.js
。我一定是在做一些非常愚蠢或明显的事情而无法看到它。
错误:
invoicer
good request
1) "before all" hook
0 passing (9ms)
1 failing
1) invoicer good request "before all" hook:
Error: Cannot find module '../index.js'
at Function.Module._resolveFilename (module.js:338:15)
at Proxyquire._disableModuleCache (/Users/mario/projects/_invoice/print-invoice/node_modules/proxyquire/lib/proxyquire.js:218:19)
at Proxyquire._disableCache (/Users/mario/projects/_invoice/print-invoice/node_modules/proxyquire/lib/proxyquire.js:203:15)
at Proxyquire._withoutCache (/Users/mario/projects/_invoice/print-invoice/node_modules/proxyquire/lib/proxyquire.js:173:27)
at Proxyquire.load (/Users/mario/projects/_invoice/print-invoice/node_modules/proxyquire/lib/proxyquire.js:135:15)
at getTestedModule (/Users/mario/projects/_invoice/print-invoice/test/test.js:89:12)
at Context.<anonymous> (/Users/mario/projects/_invoice/print-invoice/test/test.js:69:28)
at Hook.Runnable.run (/usr/local/lib/node_modules/mocha/lib/runnable.js:218:15)
at next (/usr/local/lib/node_modules/mocha/lib/runner.js:259:10)
at Object._onImmediate (/usr/local/lib/node_modules/mocha/lib/runner.js:276:5)
at processImmediate [as _immediateCallback] (timers.js:345:15)
Run Code Online (Sandbox Code Playgroud)
奇怪的是,我对另一个应用程序的测试进行了相同的设置,并且在那里找到模块没有问题。我什至维护了相同版本的proxyquire
,将其更改为最新版本仍然没有修复它。index.js
存在于指定路径的目录中。
这是我的测试代码:
var chai = require('chai');
var sinonChai = require("sinon-chai");
var …
Run Code Online (Sandbox Code Playgroud) 作为 Docker 和 VM 的新手,我遇到了阻碍。我有一个节点应用程序需要将POST
请求从 a发送Docker container
到 aVirtual Machine
或到我的local machine
.
我已经通读了 Docker 文档,但仍然不明白我需要做什么才能实现这一点。
那么如何将http
请求从运行在 a 中的节点应用程序发送Docker Container
到我的Vagrant Box
?
我被要求在一个现有的aws amplify
reactJs
项目上工作。通常我会简单地从 github 或 bitbucket 克隆项目 repo,但这个项目是 am amplify 项目,需要一整套配置。我在 cli 上设置了几个 aws 配置文件,并且可以访问此项目的 aws cludservices,但无法在本地运行该应用程序,因为我的aws-exports.js
文件中没有所需的身份验证配置。
根据现有项目的放大 cli 文档,我应该能够运行amplify init --app https://bitbucket.org/brooklynva/brooklyn-ocr-poc.git
. 然而,这尝试更新 aws 上的 cloudformation 堆栈,但幸运的是失败了。它更新了aws-exports.js
文件,但仅限于此:
// WARNING: DO NOT EDIT. This file is automatically generated by AWS Amplify. It will be overwritten.
const awsmobile = {
"aws_project_region": "us-east-2"
};
export default awsmobile;
Run Code Online (Sandbox Code Playgroud)
因此,我发现amplify pull --frontend
使用我放入 bash 文件的其他一些参数运行将等同于运行git pull
. 运行该命令后,配置文件中仍然没有任何更新。
#!/bin/bash
set -e
IFS='|' …
Run Code Online (Sandbox Code Playgroud) 我正在尝试验证hmac
从shopify
webhook
开发环境中发送的代码。但是shopify
不会向webhook
非实时端点发送对 a 的 post 请求,因此我使用requestbin来捕获请求,然后将postman
其发送到我的本地网络服务器。
从 shopify文档来看,我似乎一切都做得对,并且还尝试应用node-shopify-auth verifyWebhookHMAC 函数中使用的方法。但到目前为止,这些都没有奏效。代码永远不会匹配。我在这里做错了什么?
我验证网络钩子的代码:
function verifyWebHook(req, res, next) {
var message = JSON.stringify(req.body);
//Shopify seems to be escaping forward slashes when the build the HMAC
// so we need to do the same otherwise it will fail validation
// Shopify also seems to replace '&' with \u0026 ...
//message = message.replace('/', '\\/');
message = message.split('/').join('\\/');
message …
Run Code Online (Sandbox Code Playgroud) 我有一个expressjs
带有以下routes
和middleware
模块的应用程序.我想测试使用的路由模块mocha
,chai
,http-chai
和sinonjs
.API使用mysql
并且为了测试路由模块,我将它全部模块化,以便我可以存根mysql模块.但是,当我试图存根时middleware/index
,我遇到了麻烦.如果我尝试index
正常要求,模块实际上并没有被截断.如果我尝试使用它require.cache[require.resolve('./../../lib/routes/middleware/index')];
,它似乎存根,但indexStub.returns(indexObj)
返回错误TypeError: indexStub.returns is not a function
和TypeError: indexStub.restore is not a function
.
如何index.js
正确地存根以控制代码流并防止它尝试连接到mysql?
routes.js
'use strict';
const express = require('express');
const router = express.Router();
const configs = require('./../config/configs');
const middleware = require('./middleware/index');
const bodyParser = require('body-parser');
const useBodyParserJson = bodyParser.json({
verify: function (req, res, buf, encoding) {
req.rawBody = buf;
} …
Run Code Online (Sandbox Code Playgroud) 在我正在使用的 appsync api 的 graphQl 模式中,我想根据用户所属的组来限制他们的操作。
根据文档,添加该行aws_auth(cognito_groups: ["Admins"])
应该将访问权限限制为仅属于“管理员”组的用户。当我从 appsync 控制台或应用程序本身运行突变时,不会发生这种情况。
我的突变如下:
type Mutation @aws_iam
@aws_cognito_user_pools {
createItem(input: CreateItemInput!): Item
updateItem(input: UpdateItemInput!): Item
@aws_auth(cognito_groups: ["Admins"])
}
Run Code Online (Sandbox Code Playgroud)
@aws_iam 和 @aws_cognito_user_pools 指令似乎工作正常。但任何已通过身份验证或具有 iam 角色的人仍然可以执行更新,即使他们不属于“管理员”组。
这里发生了什么?是否需要进行额外的配置才能使其正常工作?
node.js ×5
docker ×2
api ×1
aws-amplify ×1
aws-appsync ×1
aws-lambda ×1
aws-sdk ×1
bash ×1
chai ×1
hmac ×1
http ×1
linux ×1
mysql ×1
proxyquire ×1
rest ×1
shopify ×1
sinon ×1
unit-testing ×1
vagrant ×1
webhooks ×1