Reputation: 37
In my case, AWS API Gateway should proxy every request and response through as they are. The API was created by importing an OpenAPI definition. I know how to manually set the method integration in the AWS console to HTTP proxy and set the endpoint URI.
I want to get rid of manual work and create a PowerShell script that loops through every method and sets those settings. But I haven't found the right command to update the integration type and URI.
After reading AWS CLI reference I have tried this command:
update-integration --rest-api-id x0cm5muxxx --resource-id xvxxxx --http-method GET --integration-type HTTP_PROXY --profile user2
But it gives an error:
"Unknown options: --integration-type, HTTP_PROXY"
Another CLI command I have tried without success is update-method
with --patch-operations
.
After the changes, the method's integration should look like this example:
PS C:\WINDOWS\system32> aws apigateway get-integration --rest-api-id x0cm5muxxx --resource-id x1lxxx --http-method GET --profile user2
{
"type": "HTTP_PROXY",
"httpMethod": "GET",
"uri": "https://${stageVariables.Url}/api/v1/Productlist/CanOrder/{fnprodId}",
"connectionType": "INTERNET",
"requestParameters": {
"integration.request.path.fnprodId": "method.request.path.fnprodId"
},
"passthroughBehavior": "WHEN_NO_MATCH",
"timeoutInMillis": 29000,
"cacheNamespace": "01lxxx",
"cacheKeyParameters": [],
"integrationResponses": {
"200": {
"statusCode": "200"
}
}
}
The next problem will be how to loop through every single method in the API for this update.
Upvotes: 1
Views: 1077
Reputation: 37
I got help and correct command to change methods integration type is:
aws apigateway put-integration --rest-api-id $RestAPIid --resource-id $ResourceId --http-method GET --type HTTP_PROXY --integration-http-method GET --profile $Profile --uri $uri
Edit: It have to be considered that put-integration command will lose all previous integration parameters. So after adding HTTP_PROXY integration I loop through all parameters and write them back.
If someone is trying to loop Rest API resources with Powershell it goes like this simplified..
$array = Aws apigateway get-resources --rest-api-id $RestAPIid --profile $MyProfile --query [items[*].id]
$array | sort
"Resources:"
$array
""
"Amount of resources:"
echo $array.Length
""
foreach ($arrayItem in $array) {
"$arrayItem = " + $arrayItem.length
}
Upvotes: 0