Erhebliche Importdiskrepanz in Python CDK v2 beim Aktivieren der API-Gateway-ProtokollierungPython

Python-Programme
Anonymous
 Erhebliche Importdiskrepanz in Python CDK v2 beim Aktivieren der API-Gateway-Protokollierung

Post by Anonymous »

Ich habe einen AWS CDK v2-Stack (Python) geändert, um eine API Gateway v2-Stufe mit aktivierter Protokollierung zu generieren. Klingt einfach, es gibt unzählige Beispiele im Internet und unzählige Agenten-Codierungstools, die bereit sind, es zu generieren. Dennoch funktioniert bei mir keines davon.
Mein vorhandenes CDK-Snippet sieht so aus:

Code: Select all

  # HTTP API Gateway with logging enabled
http_api = apigwv2.HttpApi(
self, "ServiceHttpApi",
api_name="ServiceApi",
description="API Gateway for Service"
)
mit Importen:

Code: Select all

import aws_cdk as cdk
from aws_cdk import (
aws_ecs as ecs,
aws_ec2 as ec2,
aws_ecr_assets as ecr_assets,
aws_logs as logs,
aws_certificatemanager as acm,
aws_elasticloadbalancingv2 as elbv2,
aws_apigatewayv2 as apigwv2,
aws_apigateway as apigwv1,
aws_apigatewayv2_integrations as apigwv2_integrations,
aws_iam as iam
)
from constructs import Construct
import os
Was ich mit so etwas erweitere (unzählige andere Permutationen ausprobiert):

Code: Select all

  # HTTP API Gateway with logging enabled
http_api = apigwv2.HttpApi(
self, "ServiceHttpApi",
api_name="ServiceApi",
description="API Gateway for Service"
)

stage = apigwv2.HttpStage(self, "Stage",
http_api=http_api,
access_log_settings=apigwv2.AccessLogSettings(
destination=apigwv2.LogGroupLogDestination(api_log_group),
format=apigwv2.AccessLogFormat.json_with_standard_fields()
)
)
Zu den Fehlern, die ich erhalte, gehören:

Code: Select all

'aws_cdk.aws_apigatewayv2' has no attribute 'AccessLogSettings'
'aws_cdk.aws_apigatewayv2' has no attribute 'AccessLogFormat'
Zusätzlich zur Überprüfung, dass meine Versionen akzeptabel waren:

Code: Select all

aws-cdk-lib>=2.220.0,=10.0.0,>> import aws_cdk
>>>  dir(aws_cdk.aws_apigatewayv2)
['AccessLogDestinationConfig', 'AddApiKeyOptions', 'AddRoutesOptions', 'ApiGatewayManagedOverridesReference', 'ApiKey', 'ApiKeyOptions', 'ApiKeyProps', 'ApiMapping', 'ApiMappingAttributes', 'ApiMappingProps', 'ApiMappingReference', 'ApiReference', 'AuthorizerPayloadVersion', 'AuthorizerReference', 'BatchHttpRouteOptions', 'CfnApi', 'CfnApiGatewayManagedOverrides', 'CfnApiGatewayManagedOverridesProps', 'CfnApiMapping', 'CfnApiMappingProps', 'CfnApiProps', 'CfnAuthorizer', 'CfnAuthorizerProps', 'CfnDeployment', 'CfnDeploymentProps', 'CfnDomainName', 'CfnDomainNameProps', 'CfnIntegration', 'CfnIntegrationProps', 'CfnIntegrationResponse', 'CfnIntegrationResponseProps', 'CfnModel', 'CfnModelProps', 'CfnRoute', 'CfnRouteProps', 'CfnRouteResponse', 'CfnRouteResponseProps', 'CfnRoutingRule', 'CfnRoutingRuleProps', 'CfnStage', 'CfnStageProps', 'CfnVpcLink', 'CfnVpcLinkProps', 'ContentHandling', 'CorsHttpMethod', 'CorsPreflightOptions', 'DeploymentReference', 'DomainMappingOptions', 'DomainName', 'DomainNameAttributes', 'DomainNameProps', 'DomainNameReference', 'EndpointOptions', 'EndpointType', 'GrantInvokeOptions', 'HttpApi', 'HttpApiAttributes', 'HttpApiProps', 'HttpAuthorizer', 'HttpAuthorizerAttributes', 'HttpAuthorizerProps', 'HttpAuthorizerType', 'HttpConnectionType', 'HttpIntegration', 'HttpIntegrationProps', 'HttpIntegrationSubtype', 'HttpIntegrationType', 'HttpMethod', 'HttpNoneAuthorizer', 'HttpRoute', 'HttpRouteAuthorizerBindOptions', 'HttpRouteAuthorizerConfig', 'HttpRouteIntegration', 'HttpRouteIntegrationBindOptions', 'HttpRouteIntegrationConfig', 'HttpRouteKey', 'HttpRouteProps', 'HttpStage', 'HttpStageAttributes', 'HttpStageOptions', 'HttpStageProps', 'IAccessLogDestination', 'IAccessLogSettings', 'IApi', 'IApiGatewayManagedOverridesRef', 'IApiKey', 'IApiMapping', 'IApiMappingRef', 'IApiRef', 'IAuthorizer', 'IAuthorizerRef', 'IDeploymentRef', 'IDomainName', 'IDomainNameRef', 'IHttpApi', 'IHttpAuthorizer', 'IHttpIntegration', 'IHttpRoute', 'IHttpRouteAuthorizer', 'IHttpStage', 'IIntegration', 'IIntegrationRef', 'IIntegrationResponseRef', 'IMappingValue', 'IModelRef', 'IRoute', 'IRouteRef', 'IRouteResponseRef', 'IRoutingRuleRef', 'IStage', 'IStageRef', 'IUsagePlan', 'IVpcLink', 'IVpcLinkRef', 'IWebSocketApi', 'IWebSocketAuthorizer', 'IWebSocketIntegration', 'IWebSocketRoute', 'IWebSocketRouteAuthorizer', 'IWebSocketStage', 'IntegrationCredentials', 'IntegrationReference', 'IntegrationResponseReference', 'IpAddressType', 'LogGroupLogDestination', 'MTLSConfig', 'MappingValue', 'ModelReference', 'ParameterMapping', 'PassthroughBehavior', 'PayloadFormatVersion', 'Period', 'QuotaSettings', 'RateLimitedApiKey', 'RateLimitedApiKeyProps', 'RouteReference', 'RouteResponseReference', 'RoutingRuleReference', 'SecurityPolicy', 'StageAttributes', 'StageOptions', 'StageReference', 'ThrottleSettings', 'UsagePlan', 'UsagePlanPerApiStage', 'UsagePlanProps', 'VpcLink', 'VpcLinkAttributes', 'VpcLinkProps', 'VpcLinkReference', 'WebSocketApi', 'WebSocketApiAttributes', 'WebSocketApiKeySelectionExpression', 'WebSocketApiProps', 'WebSocketAuthorizer', 'WebSocketAuthorizerAttributes', 'WebSocketAuthorizerProps', 'WebSocketAuthorizerType', 'WebSocketIntegration', 'WebSocketIntegrationProps', 'WebSocketIntegrationType', 'WebSocketNoneAuthorizer', 'WebSocketRoute', 'WebSocketRouteAuthorizerBindOptions', 'WebSocketRouteAuthorizerConfig', 'WebSocketRouteIntegration', 'WebSocketRouteIntegrationBindOptions', 'WebSocketRouteIntegrationConfig', 'WebSocketRouteOptions', 'WebSocketRouteProps', 'WebSocketStage', 'WebSocketStageAttributes', 'WebSocketStageProps', '__all__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '_private']
Es gibt Schnittstellen wie IAccessLogSettings, aber diese Objekte (AccessLogSettings, AccessLogFormat), von denen die AWS-Dokumentation und unzählige Google-Suchanfragen behaupten, dass sie vorhanden sein sollten, sind nicht vorhanden.
Nehmen Sie dieses Beispiel von Gemini (ich habe ähnliches von Claude, GPT erhalten), das dem gleichen Format folgt. Dies erzeugt auch die gleichen Fehler.

Code: Select all

    from aws_cdk import aws_apigatewayv2 as apigwv2

# Assuming 'http_api' is your existing apigwv2.HttpApi instance
# and 'log_group' is the LogGroup created in the previous step.

stage = apigwv2.HttpStage(
self,
"MyHttpStage",
http_api=http_api,
stage_name="dev",  # Or your desired stage name
access_log_settings=apigwv2.AccessLogSettings(
destination=apigwv2.LogGroupLogDestination(log_group),
format=apigwv2.AccessLogFormat.json_with_standard_fields(
caller=True,
http_method=True,
ip=True,
protocol=True,
request_time=date_time=True,
resource_path=True,
response_length=True,
status=True,
user=True,
),
),
)
Hier ist eine vollständige CDK-Synth-Ausgabe, falls sie hilfreich ist.

Code: Select all

% cdk synth
Traceback (most recent call last):
File "/.../cdk.py", line 9, in 
ServiceStack(app, "ServiceStack", env=ServiceEnv.get_env())
File "/.../.pyenv/versions/3.12.12/lib/python3.12/site-packages/jsii/_runtime.py", line 118, in __call__
inst = super(JSIIMeta, cast(JSIIMeta, cls)).__call__(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/.../cdk/stack.py", line 151, in __init__
access_log_settings=apigwv2.AccessLogSettings(
^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'aws_cdk.aws_apigatewayv2' has no attribute 'AccessLogSettings'. Did you mean: 'IAccessLogSettings'?
Plattform: Mac M4 Pro
Python-Version: 3.12.12
CDK-Version: 2.220.0
Dieses Problem besteht weiterhin auf einem Linux-basierten CI-Bereitstellungssystem und ist daher nicht spezifisch für meine lokale Box. Ich bin damit an eine Wand gestoßen. Ich bin neu bei Python CDK, aber weder bei Python noch bei CDK einzeln.
Was verursacht diese Diskrepanz zwischen der veröffentlichten Dokumentation für CDK und dem, was meine Umgebung anscheinend importiert hat?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post