Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

1.3K
Visualizações
AWS CDK API Gateway - how to deploy API without creating default deployment (python)

I'm trying to deploy a lambda rest api with my own deployment and I don't want to use the default deployment that is created for you when deploy=True. I'm running into weird errors when trying to explicitly define my own deployment. Here is my stack so far:

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
    )

From other posts I've read, I think I need to attach my stage or deployment to the api but there are no methods with this functionality. I tried doing api_gateway.deployment_stage = stage but that didn't work. CDK is quite new so not much out there, any help would be appreciated.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

api_gateway.deployment_stage = stage should be creating stage name api.

Is your API_gateway creating stage name prod?

Try removing this.
deployment.add_to_logical_id(str(api_gateway.latest_deployment))

over 4 years ago · Santiago Trujillo Relatório

0

below will work:

        api_gateway.add_usage_plan(
         id="UsagePlan",
         name="poc-voice-qa-usage-plan",
         description="poc usage plan",
         api_stages=[apigw.UsagePlanPerApiStage(stage=api_gateway.deployment_stage)]
        )
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda