我正在开发一个 cdk 部署脚本,我有一些工作,但我迷失了/没有运气设置不同的阶段并将不同的 lambda 应用到 api 资源。
所以我有
// Construct lambdas - prod
const lambdaBacklogGet = new lambdajs.NodejsFunction(this, "name", {
nodeModules: ['axios'],
entry: './src/path/index.js',
handler: 'handler',
runtime: lambda.Runtime.NODEJS_12_X,
timeout: cdk.Duration.seconds(20),
role: webformRole
});
// Construct lambdas - dev
const devLambdaBacklogGet = new lambdajs.NodejsFunction(this, "name-dev", {
nodeModules: ['axios'],
entry: './src/path/index.js',
handler: 'handler',
runtime: lambda.Runtime.NODEJS_12_X,
timeout: cdk.Duration.seconds(20),
role: webformRole
});
// then I Construct API
const api = new apiGateway.RestApi(this, "name-api", {
defaultCorsPreflightOptions: {
allowOrigins: apiGateway.Cors.ALL_ORIGINS,
allowHeaders: apiGateway.Cors.DEFAULT_HEADERS,
allowMethods: apiGateway.Cors.ALL_METHODS,
},
description: …Run Code Online (Sandbox Code Playgroud) 我尝试使用 jsonschema 和 python_jsonschema_objects 库从架构文件创建 python 对象,填充该对象中的一些数据,然后根据原始架构验证它。不知怎的,我觉得我做错了什么,但不确定到底是什么。
我尝试了几种不同的模式和数据值以及使用平面/单个对象删除数组。验证仍然失败。
from jsonschema import validate
import python_jsonschema_objects as pjs
import jsonschema
import json
import os
with open('geocoordinate/geocoordinatearray3.schema.json') as opfile:
schema = json.load(opfile)
builder = pjs.ObjectBuilder(schema)
ns = builder.build_classes()
Coordinate = ns.Rootschema
ca = Coordinate(latitude=22.22,longitude=33.33)
print(ca.serialize())
try:
print("about to validate first example")
validate(instance=ca, schema=schema)
except jsonschema.exceptions. ValidationError as e:
print("this is validation error:", e)
except json.decorder.JSONDecodeError as e:
print("not JSON", e)
Run Code Online (Sandbox Code Playgroud)
这是架构文件:
{
"definitions": {},
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://example.com/root.json",
"type": "object",
"title": "rootSchema",
"required": …Run Code Online (Sandbox Code Playgroud)