我将 REST API Lambda 函数部署到私有子网,其中 API 网关类型为私有。在此之后,我设置了一个 vpc 端点到私有 API 网关,连接到与 lambda 函数私有子网相同的 vpc 的两个公共子网。vpce 对应的安全组允许所有流量。
如果我尝试从公有子网中的 EC2 实例查询 API 端点,我会收到以下错误:
anonymous is not authorized to perform: execute-api:Invoke on the resource.
Run Code Online (Sandbox Code Playgroud)
我找不到问题,因为私有 API 网关的资源策略如下所示:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "execute-api:Invoke",
"Resource": "arn:aws:execute-api:eu-central-1:xxxxxxx:xxxxxx/*",
"Condition": {
"StringEquals": {
"aws:sourceVpce": "vpce-xxxxxxxx"
}
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
我正在使用set -o allexport; source .env; set +o allexport从 .env 文件中导出所有变量。不幸的是,一个变量包含)它导致语法错误的原因。上面的命令有解决方案吗?我知道可以在括号中设置它,但是 .env 是在没有括号的情况下自动生成的。
例如,Dotenv 看起来像这样:
username=test
password=*fdas_dfar+)mbn
Run Code Online (Sandbox Code Playgroud) 一些用fsolve解决非线性方程组的假设示例:
from scipy.optimize import fsolve
import math
def equations(p):
x, y = p
return (x+y**2-4, math.exp(x) + x*y - 3)
x, y = fsolve(equations, (1, 1))
print(equations((x, y)))
Run Code Online (Sandbox Code Playgroud)
是否可以使用scipy.optimize.brentq一定间隔(例如[-1,1])来解决?在这种情况下,拆包如何工作?
所以我想同时迭代两个列表,并且我还需要索引,如以下代码所示。两者对我来说都很简单,但是在第二种情况下是否也可以使用枚举?当然,假设两个 var 数组的长度相同。
import numpy as np
def _eqn(y, variables, sign=-1.0):
f = 0
for i,x in enumerate(variables):
f += x/(1+0.06)**(i+1)
return float(sign*(y + f))
_eqn(1,np.array([1,1]))
def _eqn2(y, vars1, vars2, sign=-1.0):
f = 0
n = len(vars1)
for x,y,i in zip(vars1, vars2, range(n)):
f += (x+y)/(1+0.06)**(i+1)
return float(sign*(y + f))
_eqn2(1,np.array([1,1]),np.array([1,1]))
Run Code Online (Sandbox Code Playgroud) 我正在尝试添加列表反应材料 ui组件的辅助文本的第二行。
我该如何修改它?在此处查看现场演示。
<ListItemText primary="Photos" secondary="first row" secondary="second row"/>
Run Code Online (Sandbox Code Playgroud) 我想使用数据迁移来添加和删除组。
from django.db import migrations
from django.contrib.auth.models import Group
groups = ["Test Group"]
def add_groups(apps, schema_editor):
# https://code.djangoproject.com/ticket/23422
for group in groups:
group, created = Group.objects.get_or_create(name=group)
if created:
print(f'Adding group {group}')
class Migration(migrations.Migration):
operations = [
migrations.RunPython(add_groups),
]
Run Code Online (Sandbox Code Playgroud)
该函数使用外部作用域中的变量。我想将该函数移到其他地方,以便我可以在新的迁移中重用它。但是,我似乎无法将任何参数传递给 RunPython 中的函数。我怎样才能做到这一点migrations.RunPython(add_groups(groups=groups))?
我想将矢量化操作用于高效的代码,在这里我对不同大小的数组进行操作,因此需要对数组进行切片。但是,我想调整函数,以便我可以使用平面 numpy 数组以及具有 n 行的数组进行计算。我在这个例子中使用了简单的数字,但将在我的项目中使用随机数生成。目前我已经使用 if 语句解决了它,以根据形状区分切片。没有 if 语句有没有更有效的方法?
import numpy as np
def func(a, b, c, d):
if len(a.shape) == 1:
cf = -c
cf[:len(b)] += a - b
cf[-len(d)] -= d
else:
cf = -c
cf[:, :b.shape[1]] += a - b
cf[:, -d.shape[1]:] -= d
return cf
a = np.array([1, 1, 1, 1, 1, 1, 1])
b = np.array([2, 2, 2, 2, 2, 2, 2])
c = np.array([3, 3, 3, 3, 3, 3, 3, 3])
d = np.array([4]) …Run Code Online (Sandbox Code Playgroud) 我想在使用打字稿的反应中重现这个highmaps 示例。然而,纬度/经度点没有显示出来,这似乎与 proj4 包有关,因为它在这个 javascript演示中工作。
我已经在现场演示中尝试过。如果我按如下方式加载包,它没有被使用,但我不知道应该在哪里调用它:
import * as proj4 from "proj4";
Run Code Online (Sandbox Code Playgroud)
提前致谢!
python ×4
reactjs ×2
amazon-vpc ×1
bash ×1
django ×1
enumerate ×1
highcharts ×1
linux ×1
loops ×1
material-ui ×1
migration ×1
numpy ×1
proj ×1
scipy ×1
typescript ×1