Google App Engine respond with the code 308 - email

Problem
1.I have a sns service which is running on Google App Engine
2.The sns service is using go to run as the back ending side
3.The sns service is using a crob job to request Api A
4.The Api A is adding another http request(request to Api B) into taskqueue
5.The taskqueue is executed immediately after the request of Api A
6.The request of Api B is executed
7.The Api B responded with the code 308
Problem Summary
job cron(request for Api A) -> Api A -> Task queue(stack request for Api B) ->Api B -> some execution
Api A responded with 200
Api B responded with 308
Question
Why Api B is respond with the code of 308?
Complement
By the way the following sequence is successful
post man (request for Api A) -> Api A -> Task queue(request for Api B) ->Api B -> some execution
Api A responded with 200
Api B responded with 200
When I use post man to request Api A the following request for Api B was respond with 200
The way I did with taskqueue is like
params := url.Values{}
params.Set("dollSpaces", strings.Join(dollSpaces, ","))
t := taskqueue.NewPOSTTask("/path", params)
req.Header.Set("X-AppEngine-QueueName", "mailqueue")
c := appengine.NewContext(req)
taskqueue.Add(c, t, "my queue")
The Log from Google Cloud Platform is like the following
Response of Api A
2019-01-01 10:00:00.001 JST
GET
200
193 B
577 ms
AppEngine-Google; (+http://code.google.com/appengine)
/path/ApiAPath
0.1.0.1 - - [01/Jan/2019:10:00:00 +0900] "GET /path/ApiAPath HTTP/1.1" 200 193 - "AppEngine-Google; (+http://code.google.com/appengine)" "aaa.aaa.com" ms=577 cpu_ms=3 cpm_usd=2.8039999999999998e-8 loading_request=0 instance=asda1231313asdasd123123asda123 app_engine_release=1.9.71 trace_id=123123123dsfasf123123zafasdasd
Response of Api B
2019-01-01 10:00:00.100 JST
POST
308
95 B
2 ms
AppEngine-Google; (+http://code.google.com/appengine)
/ApiBPath
0.1.0.2 - - [01/Jan/2019:10:00:00 +0900] "POST /ApiBPath HTTP/1.1" 308 95 http://aaa.aaa.com/path/ApiAPath "AppEngine-Google; (+http://code.google.com/appengine)" "aaa.aaa.com" ms=2 cpu_ms=221 cpm_usd=1.3802e-8 loading_request=0 instance= asda1231313asdasd123123asda123 app_engine_release=1.9.71 trace_id= 123123123dsfasf123123zafasdasd

Related

Rest API: 406 Unacceptable: Abacus API

I am using Abacus API (Tool for EA) to get components.
Following is documentation of API:
GET /Components({EEID})/Properties
EEID: integer (int64) x ≥ 1
in path
EEID of the component whose properties to return
200 OK
CElementProperty
OK
type CElementProperty
401 Unauthorized
Bearer token is missing or expired (unauthorized)
The /components is working fine with Bearer Token as well as /create.
But when i hit above then I get 406 Unacceptable.
Postman generates following (Also tried on ARC and same):
Same errors for component/eeid/properties
I have removed all headers and then also get same issue (on host i get bad request)
What more can i do to verify this error?

Facebook Insights API - getting error code 1 with subcode 99

We are retrieving Insights data via the Facebook Marketing API. We are using the Python "facebookads" module for this. I was downloading historic data in the past for all of our accounts which was working perfectly fine. Since 2 weeks or so I am getting this error:
2018-06-01 16:01:57 - (DEBUG) - urllib3.connectionpool - https://graph.facebook.com:443 "GET /v2.11/act_nnnn/insights?access_token=&appsecret_proof=&time_range=%7B%22since%22%3A%222018-05-08%22%2C%22until%22%3A%222018-05-08%22%7D&level=ad&breakdowns=%5B%22impression_device%22%5D&filtering=%5B%7B%22field%22%3A%22spend%22%2C%22operator%22%3A%22GREATER_THAN%22%2C%22value%22%3A%220%22%7D%5D&limit=5000&fields=account_id%2Ccampaign_id%2Ccampaign_name%2Cadset_id%2Cadset_name%2Cad_id%2Cad_name%2Cimpressions%2Cclicks%2Creach%2Cspend%2Caccount_currency%2Cactions%2Caction_values%2Ctotal_actions%2Ctotal_action_value HTTP/1.1" 500 77
2018-06-01 16:01:57 - (DEBUG) - FacebookAdsDownloader - An exception occurred:
Message: Call was not successful
Method: GET
Path: https://graph.facebook.com/v2.11/act_nnnn/insights
Params: {'time_range': '{"since":"2018-05-08","until":"2018-05-08"}', 'level': 'ad', 'breakdowns': '["impression_device"]', 'filtering': '[{"field":"spend","operator":"GREATER_THAN","value":"0"}]', 'limit': 5000, 'fields': 'account_id,campaign_id,campaign_name,adset_id,adset_name,ad_id,ad_name,impressions,clicks,reach,spend,account_currency,actions,action_values,total_actions,total_action_value'}
Status: 500
Response:
{
"error": {
"code": 1,
"message": "An unknown error occurred",
"error_subcode": 99
}
}
Anyone has an idea, why I get this error? This very same request was working already. I have retried the same request over and over.
Shireesh Asthana from Facebook Developer team mentions here that too much data is requested and asynchronous requests have to be used.
Example can be found here: retrieve async ads insights results from FB ads API with pagination

What http status should I return if client does not follow the rules?

For example, we have an API POST /test, which only accept name: AA or name: BB headers.
If a client send a name: CC header, which status code is preferred?
400? 404? 500?
If is a permission problem maybe you can send 403 (forbidden). 404 is not found and is not the correct meaning of that and 500 is a server error.

API Gateway Mock Integration Fails with 500

I have an API Gateway integration for a method/resource which works when I call it from the API but not when I actually call it:
$ aws apigateway test-invoke-method --rest-api-id $REST_API_ID \
--resource-id $RESOURCE_ID --http-method GET | jq -r .log,.body
This works out fine and I get the following output:
Tue May 16 17:46:42 UTC 2017 : Starting execution for request: test-invoke-request
Tue May 16 17:46:42 UTC 2017 : HTTP Method: GET, Resource Path: /status.json
Tue May 16 17:46:42 UTC 2017 : Method request path: {}
Tue May 16 17:46:42 UTC 2017 : Method request query string: {}
Tue May 16 17:46:42 UTC 2017 : Method request headers: {}
Tue May 16 17:46:42 UTC 2017 : Method request body before transformations:
Tue May 16 17:46:42 UTC 2017 : Endpoint response body before transformations:
Tue May 16 17:46:42 UTC 2017 : Endpoint response headers: {}
Tue May 16 17:46:42 UTC 2017 : Method response body after transformations: { "statusCode": 200 }
Tue May 16 17:46:42 UTC 2017 : Method response headers: {Content-Type=application/json}
Tue May 16 17:46:42 UTC 2017 : Successfully completed execution
Tue May 16 17:46:42 UTC 2017 : Method completed with status: 200
{ "statusCode": 200 }
However, I cannot access this at my URL, which is api.naftuli.wtf/v1/status.json. I have stages defined at glhf, stable, and v1, so by replacing that, you will see different responses. I just simply want a dummy response that returns a 200 JSON blob.
My Terraform for the resources is here as a Gist. Hopefully this fully shows my API Gateway configuration.
If I test invoke this from the CLI or from the web console, I get back what is expected. However, if I curl this from my deployed API at api.naftuli.wtf, I don't get anything nice:
$ for stage in glhf stable v1 ; do
> url="https://api.naftuli.wtf/${stage}/status.json"
> echo "${url}:"
> curl -i -H 'Content-Type: application/json' \
> https://api.naftuli.wtf/${stage}/status.json
> echo -e '\n
> done
https://api.naftuli.wtf/glhf/status.json:
HTTP/1.1 500 Internal Server Error
Content-Type: application/json
Content-Length: 36
Connection: keep-alive
Date: Tue, 16 May 2017 21:41:38 GMT
x-amzn-RequestId: 712ba52b-3a80-11e7-9fec-b79b62d3bf7f
X-Cache: Error from cloudfront
Via: 1.1 da7a5d0ed7f424609000879e43743066.cloudfront.net (CloudFront)
X-Amz-Cf-Id: hBwlbPCP9n2rlz53I-Qb9KoffHB_FoxUCZUaJYNnU3XhCWuMpQTP1Q==
{"message": "Internal server error"}
https://api.naftuli.wtf/stable/status.json:
HTTP/1.1 403 Forbidden
Content-Type: application/json
Content-Length: 23
Connection: keep-alive
Date: Tue, 16 May 2017 21:41:38 GMT
x-amzn-RequestId: 71561066-3a80-11e7-9b00-6700be628328
x-amzn-ErrorType: ForbiddenException
X-Cache: Error from cloudfront
Via: 1.1 0c146399837c7d36c1f0f9d2636f8cf8.cloudfront.net (CloudFront)
X-Amz-Cf-Id: ITX765xD8s4sNuOdXaJ2kPvqPo-w_dsQK3Sq_No130FAHxFuoVhO8w==
{"message":"Forbidden"}
https://api.naftuli.wtf/v1/status.json:
HTTP/1.1 500 Internal Server Error
Content-Type: application/json
Content-Length: 36
Connection: keep-alive
Date: Tue, 16 May 2017 21:41:39 GMT
x-amzn-RequestId: 7185fa99-3a80-11e7-a3b1-2f9e659fc361
X-Cache: Error from cloudfront
Via: 1.1 586f1a150b4ba39f3a668b8055d4d5ea.cloudfront.net (CloudFront)
X-Amz-Cf-Id: dvnOa1s-YlwLSNzBfVyx5tSL6XrjFJM4_fES7MyTofykB3ReU5R1fg==
{"message": "Internal server error"}
My understanding of stages were that they were additional path prefixes to the base path under which all API resources were available. If I had a stage called v1 with a path of /v1, I'd expect that an API Gateway resource for status.json will be basically mapped under /v1, yielding /v1/status.json.
I may be misunderstanding how API Gateway base path mappings and stages work, but CloudWatch tells me that the call is at least happening, though failing for some obscure reason:
21:41:39(c5be3842-6af4-4725-a34f-d6eea8042d17) Verifying Usage Plan for request: c5be3842-6af4-4725-a34f-d6eea8042d17. API Key: API Stage: tcips69qx2/prod_v1
21:41:39(c5be3842-6af4-4725-a34f-d6eea8042d17) API Key authorized because method 'GET /status.json' does not require API Key. Request will not contribute to throttle or quota limits
21:41:39(c5be3842-6af4-4725-a34f-d6eea8042d17) Usage Plan check succeeded for API Key and API Stage tcips69qx2/prod_v1
21:41:39(c5be3842-6af4-4725-a34f-d6eea8042d17) Starting execution for request: c5be3842-6af4-4725-a34f-d6eea8042d17
21:41:39(c5be3842-6af4-4725-a34f-d6eea8042d17) HTTP Method: GET, Resource Path: /v1/status.json
21:41:39(c5be3842-6af4-4725-a34f-d6eea8042d17) Execution failed due to configuration error: statusCode should be an integer which defined in request template
21:41:39(c5be3842-6af4-4725-a34f-d6eea8042d17) Method completed with status: 500
Apparently only traffic across the V1 stage is getting through to CloudWatch logs. I have a misconfiguration somewhere and I can't seem to find it.
Can you try and change you request template in the integration request setup to this:
{
"statusCode": 200
}
API Gateway looks for the status code to return in the response in your integration request template. The response is generated by the mapping template in the integration response. I can see from your terraform setup that you are loading the output json file in the integration request template. This is content API Gateway does not expect.
With Mock Integration Amazon API Gateway there are 2 common reasons for 500 Internal Server error.
Check the mapping template in Integration Request and ensure that you are passing statusCode as an integer to the MOCK Integration endpoint.
{
"statusCode": <Integer_Status_code>
}
Note: Make sure that status code is passed as integer not string.
Correct : 200 Incorrect : "200"
Mock Integrations do not support the binary content. If the API is enabled with bixnary support and has application/json or */* set as binaryMediaTypes, MOCK Integration endpoints would throw a 500 Internal server error when trying to transform the content.
A workaround is to update the contentHandling property of the MOCK Integration to CONVERT_TO_TEXT
Read more here :- https://cloudnamaste.com/500-internal-server-error-mock-integration/
For my case, when I deploy the lambda with serverless framework, the OPTIONS returns 200 when called. However, when I configure manually on AWS API Gateway, it returns 500 Internal Server Error.
When I check the execution log of API gateway, it said
(ee0a42d9-2cfc-4788-8679-00fbd7938cf1) Method request body before transformations: [Binary Data]
(ee0a42d9-2cfc-4788-8679-00fbd7938cf1) Execution failed due to configuration error: Unable to transform request
(ee0a42d9-2cfc-4788-8679-00fbd7938cf1) Gateway response body:
{
"message": "Internal server error"
}
After you create the Resources and OPTIONS methods, select the OPTIONS method then
At Method Execution --> Integration Request --> expand the Mapping Templates, choose "When no template matches the request Content-Type header". Add or select "application/json" in the Content-Type. Click the "application/json", and in the Generate template, paste
{statusCode: 200} without any double quote. Note, if the {"statusCode": 200} exists but with double quote, remove it to be the same as above. Then Save it
At Method Execution --> Integration Response --> expand the 200 response status --> Mapping Template --> Add or select "application/json" in the Content-Type. Make sure that the Generate template box is empty. Then Save it
At Method Execution --> Method Response --> expand the 200 response. In Response Headers for 200, add three headers: Access-Control-Allow-Headers, Access-Control-Allow-Methods, and Access-Control-Allow-Origin. Leave the Response Body for 200 to be empty
Action --> Enable CORS for the Resource
Action --> Deploy API
You have at least two distinct problems with your configuration.
First, one of your three base path mappings doesn't match the way you're trying to invoke your API. Note that the base paths don't have to be the same as your stage names, but they can be if you desire. Since your base path mappings include base paths and stage names, API Gateway is expecting the invoke path to include a base path mapping and not a stage, so it is interpreting the [glhf stable v1] portion of your path as a base path and looking for the corresponding base path mapping entry to determine the API and stage to use. This works fine for the v1 and glhf base paths which return 500 (indicating a different problem). The stable base path (in https://api.naftuli.wtf/stable/status.json) returns a 403 Forbidden because there is no base path of "stable" defined for the domain name api.naftuli.wtf. The stable stage is mapped to the "latest" base path, so calling https://api.naftuli.wtf/latest/status.json should be the way to call the stable stage. This doesn't currently work, and I don't know why. If you tell me what region your running this in, I can look-up the config and do more digging.
The second problem is indicated by the following entry from your CloudWatch logs:
Execution failed due to configuration error: statusCode should be an integer which defined in request template
Can you check that your integration request template (in the file your reference in "${file("${path.module}/files/status.json")}") contains "statusCode: 200" as a top level attribute.
I also found it surprising that you're using the same file for a request template and a response template.
Having had the identical errors I found what helped me solve this issue was to delete my OPTIONS request definition in the AWS Console. I then followed the console's "Enable CORS" form which created a new OPTIONS method.
I subsequently ran terraform plan and looked at the diff between my OPTIONS defintion and theirs. Given that the AWS Console created OPTIONS method worked I applied the changes.
Using terraform 0.12 or greater makes this possible as the terraform plan output detail is more fine grained.
I was doing this in CloudFormation.
It took me a while to get it and the accepted answer here was extremely helpful, but a little vague, so adding some more info.
Stefano Buliani's answer, in CloudFormation YAML, looks like:
RequestTemplates:
application/json: |
{ statusCode: 200 }
What was especially weird here was apparently, the fix was simply to create a deployment using the AWS CLI for each of the stages. Apparently, Terraform was not updating or re-kicking deployments on changes, and so my changes never got out.
I had a similar problem and eventually figured out that my client was using a different content type than I expected. I had foolishly assumed it would use application/json, but it was some custom json thing. In my setup, API Gateway is logging to cloudwatch, which is where I found the content type it received from the client. Once I updated the content type in the request template of the mock integration, things worked as expected.

Fi-ware 503 - Service unavailable

We are getting this 503 HTTP response:
'Error: connect ECONNREFUSED
at errnoException (net.js:901:11)
at Object.afterConnect [as oncomplete] (net.js:892:19)'
when we request: http://orion.lab.fi-ware.org:1026/v1/queryContext?limit=1000
It goes on and off, for instance, this is extracted from the logs yesterday:
14:55 – 15:39 -> 503 responses
15:51 – 16:21 -> 503 responses
15:36 – 16:50 -> 503 responses
16:55 – 16:58 -> 503 responses
17:33 – 18:37 -> 503 responses
19:16 – 19:21 -> 503 responses
20:01 – 20:13 -> 503 responses
20:52 – 21:03 -> 503 responses
21:16 – 23:26 -> 503 responses
05:04 – 05:07 -> 503 responses
We are making the request once every minute, and in those periods, every single request was a 503 and outside those, everything worked just fine.
Any ideas?
Thank you!
Orion global instance at orion.lab.fiware.org suffered some instability problems on November 17th and 18th. However, they seem to be solved now.
These temporal glitches use to happen from time to time, but they don't use to long too much. However, note that although FIWARE staff do their best to keep this instance up and stable, take into account the following disclaimer at Orion entry in the the FIWARE Catalogue:
Take into account that this is a global instance shared among all its users That means that your actions on the instance could impact to other users or viceversa. In this sense, this instance is fine to do prospective testing and to analyse the feasibility of the GEi to your purposes. However, if you are planing to use this GEi in production, please consider to deploy a dedicated instance for you in the FIWARE cloud.