gpt4 book ai didi

python-3.x - AWS CDK API 网关 - 如何在不创建默认部署的情况下部署 API(python)

转载 作者:行者123 更新时间:2023-12-04 15:23:14 30 4
gpt4 key购买 nike

我正在尝试使用我自己的部署来部署 lambda rest api,并且我不想使用在 deploy=True 时为您创建的默认部署。尝试明确定义我自己的部署时,我遇到了奇怪的错误。到目前为止,这是我的堆栈:

class Stack(core.Stack):

def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
super().__init__(scope, id, **kwargs)


# existing lambda with correct permissions
lambda_function = aws_lambda.Function.from_function_arn(self, "lambda",
"arn")

api_gateway = aws_apigateway.LambdaRestApi(
self,
id="APIGateway",
proxy=False,
description="poc apigateway",
rest_api_name="poc-voice-qa-api",
handler=lambda_function,
deploy=False
)

api_key = api_gateway.add_api_key(
id="ApiKey",
api_key_name="voice-qa-api-key"
)

deployment = aws_apigateway.Deployment(
self,
id="Deployment",
api=api_gateway
)

deployment.add_to_logical_id(str(api_gateway.latest_deployment))

stage = aws_apigateway.Stage(
self,
id="DeploymentStage",
deployment=deployment,
stage_name="api"
)

stage_usage_plan = aws_apigateway.UsagePlanPerApiStage(
api=api_gateway,
stage=stage
)

api_gateway.add_usage_plan(
id="UsagePlan",
api_key=api_key,
api_stages=[stage_usage_plan],
description="poc usage plan",
name="poc-voice-qa-usage-plan"
)

resource = api_gateway.root.add_resource(
path_part="qa"
)
resource = resource.add_resource(
path_part="test"
)

lambda_integration = aws_apigateway.LambdaIntegration(
handler=lambda_function,
passthrough_behavior=aws_apigateway.PassthroughBehavior.WHEN_NO_MATCH
)

resource.add_method(
"GET",
lambda_integration,
api_key_required=True
)

resource.add_method(
"POST",
lambda_integration,
api_key_required=True
)

从我读过的其他帖子来看,我认为我需要将我的阶段或部署附加到 api,但没有具有此功能的方法。我尝试执行 api_gateway.deployment_stage = stage 但这没有用。 CDK 非常新,所以没有太多内容,我们将不胜感激。

最佳答案

api_gateway.deployment_stage = stage 应该创建阶段名称 api

您的 API_gateway 是否正在创建阶段名称 prod

尝试删除它。
deployment.add_to_logical_id(str(api_gateway.latest_deployment))

关于python-3.x - AWS CDK API 网关 - 如何在不创建默认部署的情况下部署 API(python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62849231/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com