小编Jos*_*han的帖子

带有排序键的无服务器框架Dynamo DB表资源定义

我目前在我的serverless.yml中有一些代码.

resources:
  Resources:
    uploadBucket:
      Type: AWS::S3::Bucket
      Properties:
        BucketName: ${self:service}-${self:custom.stage}-uploads
    visitsTable:
      Type: AWS::DynamoDB::Table
      Properties:
        TableName: ${self:custom.visitsTable}
        AttributeDefinitions:
          - AttributeName: userId
            AttributeType: S
          - AttributeName: visitId
            AttributeType: S
          - AttributeName: comments
            AttributeType: S
          - AttributeName: attachments
            AttributeType: S
          - AttributeName: ph
            AttributeType: N
          - AttributeName: ch
            AttributeType: N
        KeySchema:
          - AttributeName: userId
            KeyType: HASH
          - AttributeName: visitId
            KeyType: HASH
        ProvisionedThroughput:
            ReadCapacityUnits: 5
            WriteCapacityUnits: 5
Run Code Online (Sandbox Code Playgroud)

我的目标是创建一个包含主键userId,排序键visitId的表,并包含注释,附件,ph&ch的字段.当我尝试时,sls deploy我得到以下错误.

无服务器错误---------------------------------------

发生错误:visitsTable - 属性AttributeDefinitions与表的KeySchema和二级索引不一致.

我在这做错了什么?

编辑:我试过的另一次尝试

resources:
  Resources:
    uploadBucket:
      Type: AWS::S3::Bucket
      Properties:
        BucketName: ${self:service}-${self:custom.stage}-uploads …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services amazon-dynamodb serverless-framework

6
推荐指数
1
解决办法
5360
查看次数

销毁通过Serverless创建的资源,而不会破坏Lambda端点

我在serverless.yml文件中定义了以下资源.它非常适合为我所有不同的开发阶段创建资源.

resources:
  Resources:
    uploadBucket:
      Type: AWS::S3::Bucket
      Properties:
        BucketName: ${self:service}-${self:custom.stage}-uploads
    visitsTable:
      Type: AWS::DynamoDB::Table
      Properties:
        TableName: ${self:custom.visitsTable}
        AttributeDefinitions:
          - AttributeName: userId
            AttributeType: S
          - AttributeName: visitId
            AttributeType: S
        KeySchema:
          - AttributeName: userId
            KeyType: HASH
          - AttributeName: visitId
            KeyType: RANGE
        ProvisionedThroughput:
            ReadCapacityUnits: ${self:custom.dynamoDbCapacityUnits.${self:custom.stage}}
            WriteCapacityUnits: ${self:custom.dynamoDbCapacityUnits.${self:custom.stage}}
Run Code Online (Sandbox Code Playgroud)

问题是......如果我sls remove在删除数据库时这样做,它还会删除其他所有内容,包括lambda函数及其api网关端点,我需要保留它们,因为我已经为它们明确设置了策略. 如何告诉无服务器我只想删除数据库或S3或其他任何东西而不是其余的?

我试过的事情:

我在AWS上手动删除了,但是如果你这样做并且执行sls部署它不会再次创建数据库!所以不确定最好的方法来做到这一点......

整个Serverless.yml文件

service: mydomain-api

# Use serverless-webpack plugin to transpile ES6/ES7
plugins:
  - serverless-webpack
  - serverless-domain-manager

custom:
  webpackIncludeModules: true
  stage: ${opt:stage, self:provider.stage}
  visitsTable: "${self:service}-visits-${self:custom.stage}"
  domains:
    prod: api.mydomain.com
    staging: staging-api.mydomain.com
    dev: dev-api.mydomain.com …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services aws-lambda aws-api-gateway serverless-framework serverless

6
推荐指数
2
解决办法
4823
查看次数

如何使用非主键字段查询DynamoDB?

我的dynamoDB表中有以下数据。

在此处输入图片说明

这是我的代码:

const userStatusParams = {
        TableName: process.env.USERSTATUS_TABLE,
        KeyConditionExpression: "loggedIn = :loggedIn",
        ExpressionAttributeValues: {
          ":loggedIn": true
        }
      };
      var usersResult;
      try {
        usersResult = await dynamoDbLib.call("query", userStatusParams);
        console.log(usersResult);
      }catch (e) {
        console.log("Error occurred querying for users belong to group.");
        console.log(e);
      }
Run Code Online (Sandbox Code Playgroud)

亚马逊返回此错误:

{ ValidationException: Query condition missed key schema element: userId
    at Request.extractError ...
Run Code Online (Sandbox Code Playgroud)

我如何让它返回所有登录记录== true的记录?

目前,我的数据库通过我的serverless.yml配置来构建。

phoneNumberTable: #This table is used to track phone numbers used in the system.
      Type: AWS::DynamoDB::Table
      Properties:
        TableName: ${self:custom.phoneNumberTable}
        AttributeDefinitions: #UserID in this case …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services node.js amazon-dynamodb serverless-framework

6
推荐指数
1
解决办法
5491
查看次数

Cocoa(Mac Os X)打印多页,为什么预览窗口显示2页而不是1页?

我有一个我正在研究的可可应用程序,我在其中创建了一个我要发送到打印机的customView.在子类NSView中,我也设置了一些框架选项,代码如下.我有2个全局变量来保存在main()函数外声明的打印信息.

- (id)initWithFrame:(NSRect)frame
{
    extern NSPrintInfo *globalPrintInfo;
    extern NSPrintOperation *globalPrintOperation;

    //Modify the frame before it's sent to it's super method.  Also set the global variables to there default values.
    globalPrintOperation = [NSPrintOperation printOperationWithView:self];
    globalPrintInfo = [globalPrintOperation printInfo];//Get the print information from it.

    [globalPrintInfo setBottomMargin:0.0];
    [globalPrintInfo setLeftMargin:0.0];
    [globalPrintInfo setTopMargin:0.0];
    [globalPrintInfo setRightMargin:0.0];

    [globalPrintOperation setPrintInfo:globalPrintInfo];//save the printInfo changes.

    //modify the frame to reflect the correct height & width of the paper.
    frame.size.height = globalPrintInfo.paperSize.height-globalPrintInfo.topMargin-globalPrintInfo.bottomMargin;
    frame.size.width = globalPrintInfo.paperSize.width-globalPrintInfo.leftMargin-globalPrintInfo.rightMargin;
    frame.origin.x=0;
    frame.origin.y=0;

    NSLog(@"Printer Name=%@, Printer Type=%@",globalPrintInfo.printer.name,globalPrintInfo.printer.type); …
Run Code Online (Sandbox Code Playgroud)

printing macos cocoa objective-c

5
推荐指数
1
解决办法
3858
查看次数

存储日期并从本地存储中检索

我将日期存储到本地存储,如下所示.

JS:

var currentTime = new Date(); //get the current time.

//Clock in the time.
localStorage.time = currentTime;
Run Code Online (Sandbox Code Playgroud)

当我尝试稍后使用时检索它...

var timeObj = new Date(localStorage.time);
var checkInDayOfMonth = timeObj.getUTCDate(); //returns 1-31 
Run Code Online (Sandbox Code Playgroud)

timeObj将没有正确的日期时间,而是显示当前时间,好像它忽略了我发送的时间参数.

我正在使用getUTCDate来获取当月的这一天.如果今天的价值与存储的价值不同,我知道这是新的一天.

打开Goog​​le Chrome Inspector会以以下格式显示以localStorage存储的日期:

Wed Dec 11 2013 22:17:45 GMT-0800 (PST)
Run Code Online (Sandbox Code Playgroud)

这不是日期构造函数的可接受格式吗?

如何正确存储和检索localStorage中的日期?

javascript jquery html5 date local-storage

5
推荐指数
1
解决办法
8363
查看次数

快速序列协议的Swift 2到3迁移

我正在尝试将以下代码从此库(https://github.com/dankogai/swift-json)转换为Swift 3兼容代码.

我很难弄清楚如何将Swift 2中使用的Sequence协议转换为Swift 3的正确版本.我找不到任何关于Swift 2 Sequence协议变化的文档与3相比.

这是我目前已尽可能转换为Swift 3的代码

extension JSON : Sequence {
    public func generate()->AnyIterator<(AnyObject,JSON)> {
        switch _value {
        case let o as NSArray:
            var i = -1
            return AnyIterator {
                i=i+1
                if i == o.count { return nil }
                return (i as AnyObject, JSON(o[i]))
            }
        case let o as NSDictionary:
            var ks = Array(o.allKeys.reversed())
            return AnyIterator {
                if ks.isEmpty { return nil }
                if let k = ks.removeLast() as? String {
                    return (k as AnyObject, …
Run Code Online (Sandbox Code Playgroud)

swift swift-protocols swift2 swift3 ios10

5
推荐指数
1
解决办法
699
查看次数

Docker-Compose不会为我的php.ini文件量

我正在尝试使用docker-compose来扩展我的php.ini文件,这样我就可以在我的本地机器上动态更改,看看它如何影响主机.不幸的是,到目前为止,在Dockerfile中创建时,我能够将php.ini文件放入容器的唯一方法就是直接.

附件是使用下面的当前设置正常运行的容器图像.

在此输入图像描述

我的Dockerfile如下:

FROM ubuntu:14.04
MAINTAINER Joe Astrahan <jastrahan@poolservice.software>

VOLUME ["/var/www"]


RUN apt-get update && \
    apt-get install -y software-properties-common && \
    apt-get update && \
    apt-get install -y \
      apache2 \
      curl \
      libcurl3 \
      libcurl3-dev \
      php5 \
      php5-cli \
      libapache2-mod-php5 \
      php5-gd \
      php5-json \
      php5-ldap \
      php5-mysqlnd \
      php5-pgsql \
      php5-curl \
      mysql-client

COPY config/php.ini /etc/php5/apache2/php.ini

# install php-5.5.30
COPY config/install_php-5.5.30.sh /tmp/install_php-5.5.30.sh
RUN /bin/bash /tmp/install_php-5.5.30.sh


COPY config/apache_default.conf /etc/apache2/sites-available/000-default.conf
COPY config/run /usr/local/bin/run

RUN chmod +x /usr/local/bin/run
RUN …
Run Code Online (Sandbox Code Playgroud)

php docker dockerfile docker-compose docker-volume

5
推荐指数
1
解决办法
6290
查看次数

用户的棘轮存储连接和在服务器实例外发送消息

我一直在关注这里的教程并让棘轮服务器正常工作。

我的聊天课目前或多或少与教程相同,所以在这里展示这一点没有意义,因为我的问题更多是关于实施策略

在我附加的问题中,用户正在寻找如何获取特定用户的连接对象。在最佳答案解决方案中,跟踪资源 ID 似乎是实现此目的的方法。

例如,当创建连接时,有此代码。

public function onOpen(ConnectionInterface $conn) {
        // Store the new connection to send messages to later
        $this->clients[$conn->resourceId] = $conn;
        echo "New connection! ({$conn->resourceId})\n";
    }
Run Code Online (Sandbox Code Playgroud)

这将创建一个成员变量clients来存储所有连接,您现在只需通过 ID 引用它即可发送消息。然而,这个客户是一个实例 ConnectionInterface $conn

然后要发送消息,您只需使用下面的代码输入客户端的 id 作为数组键。很简单。

$client = $this->clients[{{insert client id here}}];
$client->send("Message successfully sent to user.");
Run Code Online (Sandbox Code Playgroud)

正如我们所知,棘轮作为服务器上的脚本在一个永无止境的事件循环中运行。

我正在运行一个 Symfony 项目,其中当用户在系统中执行某个操作时,在服务器实例之外运行棘轮代码,我需要它向连接到服务器的特定客户端发送消息。

我不确定如何执行此操作,因为客户端是 ConnectionInterface 的实例,并且是在用户首次通过 WebSockets 连接时创建的。如何以这种方式向特定客户端发送消息?

这是我试图实现的目标的视觉效果。

在此处输入图片说明

参考:

如何获取特定用户的连接对象?

php websocket symfony ratchet

5
推荐指数
1
解决办法
3816
查看次数

使用与特征函数相同名称的PHP类

我有以下代码作为示例.

trait sampletrait{
   function hello(){
      echo "hello from trait";
   }
}

class client{
   use sampletrait;

   function hello(){
      echo "hello from class";
      //From within here, how do I call traits hello() function also?
   }
}
Run Code Online (Sandbox Code Playgroud)

我可以把所有细节都说明为什么这是必要的,但我想让这个问题变得简单.由于我的特殊情况,从班级客户端延伸不是答案.

是否有可能让一个特征与使用它的类具有相同的函数名称,但除了类函数之外还调用特征函数?

目前它只会使用类函数(因为它似乎覆盖了特征)

php class traits php-7 php-traits

5
推荐指数
1
解决办法
984
查看次数

无服务器警告:无法确定模块babel-runtime的版本

我正在运行sls deploy并获得以下警告,这些警告会阻塞许多行.

Serverless: WARNING: Could not determine version of module babel-runtime
Serverless: WARNING: Could not determine version of module babel-runtime
Serverless: WARNING: Could not determine version of module babel-runtime
Serverless: WARNING: Could not determine version of module babel-runtime
Serverless: WARNING: Could not determine version of module babel-runtime
...
Run Code Online (Sandbox Code Playgroud)

如果我担心,这个警告的原因是什么?我如何解决它?

(如果我需要在此问题中添加额外信息,请告诉我,我会立即编辑问题).

serverless-framework serverless

5
推荐指数
1
解决办法
1600
查看次数