小编mon*_*mon的帖子

创建 API 网关集成时出错响应:NotFoundException:指定的集成标识符无效

客观的

问题的解决方案或解决方法。

问题

如果 Firehose 是提前单独创建的,则下面的 Terraform API Gateway 与 Firehose 的集成有效。

resource "aws_api_gateway_integration" "click_put" {
  rest_api_id = data.aws_api_gateway_rest_api.mysfit.id
  resource_id = aws_api_gateway_resource.click.id
  type        = "AWS"
  uri         = "arn:aws:apigateway:${var.REGION}:firehose:action/PutRecord"
  credentials = aws_iam_role.api_click.arn

  http_method = aws_api_gateway_method.click_put.http_method
  integration_http_method = "POST"
  request_parameters = {
    "integration.request.header.Content-Type" = "'application/x-amz-json-1.1'"
  }
  passthrough_behavior = "NEVER"
  request_templates = {
    "application/json" = <<EOF
{
  "DeliveryStreamName": "${local.firehose_name}",
  "Record": {
    "Data": "$util.base64Encode($input.json('$'))"
  }
}
EOF
  }
}
...
resource "aws_api_gateway_integration_response" "click_put" {
  rest_api_id = data.aws_api_gateway_rest_api.mysfit.id
  resource_id = aws_api_gateway_resource.click.id
  http_method = aws_api_gateway_method.click_put.http_method
  status_code …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services terraform-provider-aws amazon-kinesis-firehose amazon-api-gateway

10
推荐指数
1
解决办法
6263
查看次数

理解 go 复合字面量

为什么对f 的函数值赋值不是复合文字?

Go lang规范复合文字如下所述,因此函数值不能用复合文字构造。

复合文字为结构体、数组、切片和映射构造值,并在每次求值时创建一个新值

但是,代码中对f 的函数值赋值看起来像是func() int类型的复合文字表达式。

是否存在无法将函数对象构造为复合文字的原因?

package main
import (
    "fmt"
)

func main(){
    var x int = 0

    var f func() int
    f = func() int{ x++; return x * x }  // <---- Why this cannot be a composite literal?

    fmt.Println(f())   // 1
    fmt.Println(f())   // 4
    fmt.Println(f())   // 9

    // Define a type for "func() int" type 
    type SQUARE func() int
    g := SQUARE{ x++; return x * …
Run Code Online (Sandbox Code Playgroud)

go composite-literals

10
推荐指数
2
解决办法
3万
查看次数

布尔索引行为的解释

对于二维数组 y:

y = np.arange(20).reshape(5,4)
---
[[ 0  1  2  3]
 [ 4  5  6  7]
 [ 8  9 10 11]
 [12 13 14 15]
 [16 17 18 19]]
Run Code Online (Sandbox Code Playgroud)

所有索引都选择第 1、第 3 和第 5 行。这是清楚的。

print(y[
    [0, 2, 4],
    ::
])
print(y[
    [0, 2, 4],
    ::
])
print(y[
    [True, False, True, False, True],
    ::
])
---
[[ 0  1  2  3]
 [ 8  9 10 11]
 [16 17 18 19]]
Run Code Online (Sandbox Code Playgroud)

问题

请帮助了解产生结果的规则或机制。

[]用元组替换会产生一个形状为 (0, 5, 4) 的空数组。

y[
    (True, …
Run Code Online (Sandbox Code Playgroud)

python numpy boolean-indexing

9
推荐指数
1
解决办法
116
查看次数

如何从函数列表 [f1, f2, f3,...fn] 组合嵌套函数 g=fn(...(f3(f2(f1()))...)

是否有一种现成的 Pythonic 方法可以从函数列表 [f1, f2, f3] 中组合多个嵌套函数 g = f3(f2(f1())) ,其中列表中有更多函数。

如果有几个,我可以这样做:

g = lambda x: f3(f2(f1(x)))
Run Code Online (Sandbox Code Playgroud)

然而,当我在深度神经网络中有几十个功能(例如层)时,它是无法管理的。宁愿不创建另一个函数来组合 g 而是找到一种可用的方法。


更新

基于@Chris 的回答。对于顺序神经网络层[ batchnorm, matmul, activation, softmaxloss ],每个层都有一种forward(X)计算其输出到下一层的方法,损失函数 L 和 loss 为:

L = reduce(lambda f, g: lambda X: g(f(X)),  [ layer.forward for layer in layers ] )   # Loss function
network_loss = L(X)
Run Code Online (Sandbox Code Playgroud)

python

9
推荐指数
1
解决办法
242
查看次数

GCP - 如何管理多个应用程序凭据

假设我有 5 个 Google 帐户(gmail 帐户)。有没有一种方法可以创建多个应用程序默认凭据 (ADC),每个 Google 帐户一个,并指定将哪一个用于 GCP SDK?

gcloud auth 应用程序-默认登录

通过 Web 流获取用户访问凭据,并将其放入应用程序默认凭据 (ADC) 的众所周知位置。

众所周知的地点是~/.config/gcloud/application_default_credentials.json

AWS有一个概念profile,我们可以指定--profile指定要使用哪个AWS凭证。因此想知道GCP中是否有类似的机制。

credentials google-cloud-platform gcloud

9
推荐指数
1
解决办法
1450
查看次数

如何访问etcd中的kubernetes密钥

如何从etcd获取Kubernetes相关密钥?试图列出etcd中的键,但无法看到相关的键.还在哪里安装了etcdctl?

$ etcdctl
bash: etcdctl: command not found..

$ sudo netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:2379          0.0.0.0:*               LISTEN      386/etcd            
tcp        0      0 127.0.0.1:2380          0.0.0.0:*               LISTEN      386/etcd            

$ curl -s http://localhost:2379/v2/keys | python -m json.tool
{
    "action": "get",
    "node": {
        "dir": true
    }
}
Run Code Online (Sandbox Code Playgroud)

背景

通过使用kubeadm在CentOS 7上创建群集来安装Kubernetes 1.8.5 .当我查看etcd入门时,v2/keys看起来是终点.

etcd kubernetes

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

实际上,什么是AWS Prefix?

AWS Prefix的定义在哪里?

背景

在寻找列出S3端点CIDR的方法时,遇到了AWS 前缀列表一词,但不确定其确切含义以及定义的术语。

混乱

前缀是指放在前面的单词。对于S3,根据“ 使用前缀和分隔符分层列出密钥”,它应该是对象的起始路径。

但是,它显然是指IP地址范围。前缀如何用于IP范围?历史或原因是什么?

地形aws_prefix_list

这既可以用于验证变量中给定的前缀列表,也可以用于获取关联的AWS服务的CIDR块(IP地址范围)。

描述前缀列表

以前缀列表格式描述可用的AWS服务,其中包括服务的前缀列表名称和前缀列表ID以及服务的IP地址范围。

AWS IP地址范围

SERVICE="S3"
REGION="us-west-1"
$ curl -s https://ip-ranges.amazonaws.com/ip-ranges.json | \
  jq -r --arg SERVICE "$SERVICE" --arg REGION "${REGION}" '.prefixes[] \
   | select(.service==$SERVICE and .region==$REGION)'

{
  "ip_prefix": "52.92.48.0/22",
  "region": "us-west-1",
  "service": "S3"
}
{
  "ip_prefix": "54.231.232.0/21",
  "region": "us-west-1",
  "service": "S3"
}
{
  "ip_prefix": "52.219.20.0/22",
  "region": "us-west-1",
  "service": "S3"
}
{
  "ip_prefix": "52.219.24.0/21",
  "region": "us-west-1",
  "service": "S3"
}
Run Code Online (Sandbox Code Playgroud)

更新资料

前缀是什么意思?

假设您有一个类似10.5.10.0/24的网络,因此该子网中的前缀10.5.10从1到255,网络地址将是10.5.10.0

我假设(10.0.0.0/24)表示具有254个IP地址(从1到254)的网络(32位IP的前24位部分)(0是网络,而255是广播)。前缀是前24位,后缀(?)是后8位。标识网络的高N位列表是IP前缀列表。

prefix amazon-web-services

8
推荐指数
2
解决办法
2291
查看次数

Terraform - 为什么这不会导致循环依赖?

Terraform 注册表 AWS VPC 示例terraform-aws-vpc/examples/complete-vpc/main.tf具有以下代码,在我看来,这是循环依赖项。

data "aws_security_group" "default" {
  name   = "default"
  vpc_id = module.vpc.vpc_id
}

module "vpc" {
  source = "../../"

  name = "complete-example"

...
 # VPC endpoint for SSM
  enable_ssm_endpoint              = true
  ssm_endpoint_private_dns_enabled = true
  ssm_endpoint_security_group_ids  = [data.aws_security_group.default.id] # <----- 

...
Run Code Online (Sandbox Code Playgroud)

data.aws_security_group.default指“module.vpc.vpc_id”,module.vpc指“data.aws_security_group.default.id”。

请解释为什么这不会导致错误以及 module.vpc 如何可以引用 data.aws_security_group.default.id?

terraform

8
推荐指数
1
解决办法
4421
查看次数

python 类型提示 - 可以使用tensorflow数据类型吗?

是否可以在Python类型提示中使用Tensorflow数据类型tf.dtypes.DType,例如tf.int32?

from typing import (
    Union,
)
import tensorflow as tf
import numpy as np


def f(
    a: Union[tf.int32, tf.float32]  # <----
): 
    return a * 2


def g(a: Union[np.int32, np.float32]):
    return a * 2


def test_a():
    f(tf.cast(1.0, dtype=tf.float32))  # <----
    g(np.float32(1.0))                 # Numpy type has no issue

Run Code Online (Sandbox Code Playgroud)

它会导致以下错误,并想知道这是否可能。

python3.8/typing.py:149: in _type_check
    raise TypeError(f"{msg} Got {arg!r:.100}.")
E   TypeError: Union[arg, ...]: each arg must be a type. Got tf.int32.
Run Code Online (Sandbox Code Playgroud)

python type-hinting tensorflow

8
推荐指数
1
解决办法
4716
查看次数

RHEL8.5 shell“BASH_FUNC_which%%”环境变量导致 K8S Pod 失败

问题

从 8.4 迁移到 RHEL 8.5 后,开始出现 K8S Pod 故障的问题。

spec.template.spec.containers[0].env[52].name: Invalid value: "BASH_FUNC_which%%": a valid environment variable name must 
consist of alphabetic characters, digits, '_', '-', or '.', and must not start with a digit (e.g. 'my.env-name',  or 'MY_ENV.NAME',  or 'MyEnvName1', regex used for validation is '[-._a-zA-Z][-._a-zA-Z0-9]*')
Run Code Online (Sandbox Code Playgroud)

登录 shell 中的env命令显示BASH_FUNC_which%%定义如下。

BASH_FUNC_which%%=() {  ( alias;
 eval ${which_declare} ) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot "$@"
}
Run Code Online (Sandbox Code Playgroud)

建议这/etc/profile.d/which2.sh是设置BASH_FUNC_which%%.

  • /etc/profile.d/which2.sh

# shellcheck shell=sh …
Run Code Online (Sandbox Code Playgroud)

redhat environment-variables kubernetes

8
推荐指数
1
解决办法
3056
查看次数