HTTP V2 API log format--what is proper way to quote JSON format?

0

I'm trying to set up a log on my V2 HTTP API (apigatewayv2):

aws apigatewayv2 update-stage --api-id API_ID --stage-name '$default' --access-log-settings '{"DestinationArn": "arn:aws:logs:us-west-1:ACCOINT_ID:log-group:LOG_GROUP", "Format": { "requestId":"$context.requestId", "ip": "$context.identity.sourceIp", "requestTime":"$context.requestTime", "httpMethod":"$context.httpMethod","routeKey":"$context.routeKey", "status":"$context.status","protocol":"$context.protocol", "responseLength":"$context.responseLength" }}'

where API_ID, ACCOUNT_ID, LOG_GROUP are just fake placeholders for this post. The JSON format string is right out of the online documentation.

Here's what I get. I have tried numerous quoting strategies and this (simple) one gets me closest to something that looks reasonable (but still fails):

Parameter validation failed:
Invalid type for parameter AccessLogSettings.Format, value: OrderedDict([('requestId', '$context.requestId'), ('ip','$context.identity.sourceIp'), ('requestTime', '$context.requestTime'), ('httpMethod', '$context.httpMethod'), ('routeKey','$context.routeKey'), ('status', '$context.status'), ('protocol', '$context.protocol'), ('responseLength','$context.responseLength')]), type: <class 'collections.OrderedDict'>, valid types: <class 'str'>

Anyone have an example of this that works. Unfortunately, HTTP APIs are so new that there aren't that many CLI examples out there.

Edited by: LosAlamosAl on Nov 20, 2021 4:01 PM

Edited by: LosAlamosAl on Nov 20, 2021 4:03 PM

Edited by: LosAlamosAl on Nov 20, 2021 4:03 PM

1 Antwort
1

Answering my own question. This is the quoting that is required:

aws apigatewayv2 update-stage --api-id API_ID --stage-name '$default' --access-log-settings '{"DestinationArn": "arn:aws:logs:us-west-1:ACCOUNT_ID:log-group:LOG_GROUP", "Format": "{ "requestId":"$context.requestId", "ip": "$context.identity.sourceIp", "requestTime":"$context.requestTime", "httpMethod":"$context.httpMethod","routeKey":"$context.routeKey", "status":"$context.status","protocol":"$context.protocol", "responseLength":"$context.responseLength" }"}'

Edited by: LosAlamosAl on Nov 20, 2021 4:30 PM

Edited by: LosAlamosAl on Nov 20, 2021 4:32 PM

beantwortet vor 2 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen