简体   繁体   English

使用 aws cli 创建 Kinesis Analytics 应用程序

[英]Creating Kinesis Analytics applications using aws cli

I want to create a kinesis analytics application using aws cli.我想使用 aws cli 创建一个 kinesis 分析应用程序。 I use this command to create the application我使用这个命令来创建应用程序

aws kinesisanalytics create-application --application-name smartfactorytest1 --application-code "CREATE OR REPLACE STREAM DESTINATION_SQL_STREAM ( "device_serial" VARCHAR(16), "uploadRate"  INTEGER, "downloadRate" INTEGER);
CREATE OR REPLACE PUMP "STREAM_PUMP" 
    AS INSERT INTO DESTINATION_SQL_STREAM
SELECT STREAM  "device_serial",  "uploadRate", "downloadRate"
    FROM SOURCE_SQL_STREAM_001
-- LIKE compares a string to a string pattern (_ matches all char, % matches substring)
-- SIMILAR TO compares string to a regex, may use ESCAPE
    WHERE "uploadRate" >20000" --inputs NamePrefix="SOURCE_SQL_STREAM",KinesisStreamsInput={ResourceARN="sourcearn",RoleARN="rolearn"}

But I get this error但我收到这个错误

invalid type for parameter Inputs[0].KinesisStreamsInput, value: ResourceARN=string, type: <class 'str'>, valid types: <class 'dict'>

Can anyone tell me what am I doing wrong?谁能告诉我我做错了什么? Any help would be appreciated.任何帮助,将不胜感激。

I believe the issue is either that you need to take the quotes out in the KinesisStreamsInput section, or you need to add quotes and escape them.我相信问题是您需要在KinesisStreamsInput部分中取出引号,或者您需要添加引号并转义它们。 The documentation is unclear on which is the correct option.文档不清楚哪个是正确的选项。

  1. According to the AWS Kinesis Analytics CLI Reference, https://docs.aws.amazon.com/cli/latest/reference/kinesisanalytics/create-application.html , the syntax for --inputs with KinesisStreamsInput should look like the example provided for KinesisStreamsOutput :根据 AWS Kinesis Analytics CLI 参考, https: --inputs ,-- --inputsKinesisStreamsInput的语法应该类似于提供的示例KinesisStreamsOutput

     Name=string,KinesisStreamsOutput={ResourceARN=string,RoleARN=string},...

    This would mean removing the quotes around your sourcearn and rolearn .这意味着删除sourcearnrolearn周围的引号。 However, the documentation isn't clear that this refers to the CLI syntax in all cases.但是,文档并不清楚这在所有情况下都指的是 CLI 语法。

  2. If that doesn't work, according to this AWS CLI usage guide page, https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-parameters-quoting-strings.html , it specifies adding quotes and escaping the relevant ones, depending on your OS...如果这不起作用,根据此 AWS CLI 使用指南页面https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-parameters-quoting-strings.html ,它指定添加引号并转义相关的,具体取决于您的操作系统...

    "Linux or macOS “Linux 或 macOS

    Use single quotation marks (' ') to enclose the JSON data structure, as in the following example.使用单引号 (' ') 将 JSON 数据结构括起来,如下例所示。 You don't have to do anything special with the embedded double quotation marks embedded in the JSON string.您不必对 JSON 字符串中嵌入的双引号做任何特殊处理。

     aws ec2 run-instances --image-id ami-12345678 --block-device-mappings '[{"DeviceName":"/dev/sdb","Ebs":{"VolumeSize":20,"DeleteOnTermination":false,"VolumeType":"standard"}}]'

    PowerShell电源外壳

    PowerShell requires single quotation marks (' ') to enclose the JSON data structure. PowerShell 要求使用单引号 (' ') 将 JSON 数据结构括起来。 Also, because double quotation marks have a special meaning to PowerShell, you must use a backslash () to escape each double quotation mark (") within the JSON structure, as in the following example.此外,由于双引号对 PowerShell 具有特殊含义,因此您必须使用反斜杠 () 来转义 JSON 结构中的每个双引号 ("),如下例所示。

     PS C:\\> aws ec2 run-instances --image-id ami-12345678 --block-device-mappings '[{\\"DeviceName\\":\\"/dev/sdb\\",\\"Ebs\\":{\\"VolumeSize\\":20,\\"DeleteOnTermination\\":false,\\"VolumeType\\":\\"standard\\"}}]'

    Windows Command Prompt Windows 命令提示符

    The Windows command prompt requires double quotation marks (" ") to enclose the JSON data structure. Windows 命令提示符需要使用双引号 (" ") 将 JSON 数据结构括起来。 Also, to prevent the command processor from misinterpreting the double quotation marks embedded in the JSON, you must also escape (precede with a backslash [ \\ ] character) each double quotation mark (") within the JSON data structure itself, as in the following example.此外,为了防止命令处理器误解嵌入在 JSON 中的双引号,您还必须对 JSON 数据结构本身中的每个双引号 (") 进行转义(以反斜杠 [\\] 字符开头),如下所示例子。

     C:\\> aws ec2 run-instances --image-id ami-12345678 --block-device-mappings "[{\\"DeviceName\\":\\"/dev/sdb\\",\\"Ebs\\":{\\"VolumeSize\\":20,\\"DeleteOnTermination\\":false,\\"VolumeType\\":\\"standard\\"}}]"

    Only the outermost double quotation marks are not escaped."只有最外面的双引号不会被转义。”

  3. This link also references needing to escape quotes on Windows, and is using the kinesisanalytics command: https://github.com/aws/aws-cli/issues/3103此链接还提到需要在 Windows 上转义引号,并使用kinesisanalytics命令: https : //github.com/aws/aws-cli/issues/3103

    "Rishi74744 commented on Feb 6, 2018 "Rishi74744 于 2018 年 2 月 6 日发表评论

    I got it to work as -我让它工作 -

     aws kinesisanalytics add-application-reference-data-source --endpoint https://kinesisanalytics.us-east-1.amazonaws.com --region us-east-1 --application-name alerts --reference-data-source "{\\"TableName\\":\\"DeviceData\\",\\"S3ReferenceDataSource\\":{\\"BucketARN\\":\\"arn: aws: s3: : : bucket-name\\",\\"FileKey\\":\\"device.csv\\",\\"ReferenceRoleARN\\":\\"arn: aws: iam: : account-id: role/role-name\\"},\\"ReferenceSchema\\":{\\"RecordFormat\\":{\\"RecordFormatType\\":\\"CSV\\",\\"MappingParameters\\":{\\"CSVMappingParameters\\":{\\"RecordRowDelimiter\\":\\"\\n\\",\\"RecordColumnDelimiter\\":\\", \\"}}},\\"RecordEncoding\\":\\"UTF-8\\",\\"RecordColumns\\":[{\\"Name\\":\\"key1\\",\\"SqlType\\":\\"VARCHAR(64)\\"},{\\"Name\\":\\"key2\\",\\"SqlType\\":\\"VARCHAR(64)\\"}]}}" --current-application-version-id 2

    But this should be mentioned in the documentation."但这应该在文档中提及。”

  4. One note: it may be preferable to use JSON files as inputs and use this syntax instead: --cli-input-json file://input.json .一个注意事项:最好使用 JSON 文件作为输入并使用以下语法: --cli-input-json file://input.json This is referenced in the AWS Kinesis CLI Command Reference (first link, under 1.) and also mentioned in the GitHub link above.这在 AWS Kinesis CLI 命令参考(第一个链接,在 1. 下)中被引用,也在上面的 GitHub 链接中提到。 It's also the method used by the majority of the AWS Kinesis documentation.这也是大多数 AWS Kinesis 文档使用的方法。 For example, JSON files used for different purposes in Kinesis Analytics: https://docs.aws.amazon.com/kinesisanalytics/latest/dev/how-it-works-input.html例如,在 Kinesis Analytics 中用于不同目的的 JSON 文件: https : //docs.aws.amazon.com/kinesisanalytics/latest/dev/how-it-works-input.html

Please let me know what works, and I will work with my AWS rep to improve the documentation.请告诉我什么有效,我将与我的 AWS 代表一起改进文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM