0

I have https://api-id.execute-api.region.amazonaws.com/stage endpoint, how to query it using SDK?

Found ApiGatewayClient but can't figure out how to use it properly and didn't find any helpful usage examples on the internet.

Some methods require some ConnectionID or another arguments, I am sure there should be a simple way.

EDIT For instance my Api url is https://myawesomeid.execute-api.eu-central-1.amazonaws.com/prod/ where "myawesomeid" is my ApiId. Querying it like this:

$this->client->getStage([
            'restApiId' => 'myawesomeid',
            'stageName' => 'execute-api',
        ]);

And got such error:

Error executing \"GetStage\" on \"https://apigateway.eu-central-1.amazonaws.com/restapis/myawesomeid/stages/execute-api\"; AWS HTTP error: Client error: `GET https://apigateway.eu-central-1.amazonaws.com/restapis/myawesomeid/stages/execute-api` resulted in a `403 Forbidden` response:\n{\"Message\":\"User: arn:aws:iam::804737862755:user/staging-api-s3-assets is not authorized to perform: apigateway:GET on r (truncated...)\n AccessDeniedException (client): User: arn:aws:iam::804737862755:user/staging-api-s3-assets is not authorized to perform: apigateway:GET on resource: arn:aws:apigateway:eu-central-1::/restapis/myawesomeid/stages/execute-api because no identity-based policy allows the apigateway:GET action - {\"Message\":\"User: arn:aws:iam::804737862755:user/staging-api-s3-assets is not authorized to perform: apigateway:GET on resource: arn:aws:apigateway:eu-central-1::/restapis/myawesomeid/stages/execute-api because no identity-based policy allows the apigateway:GET action\"}\n

I think I might not have enough permissions, but using Postman I can query my Api endpoint by this credentials I use to connect via code. What I need is just to make GET/POST to my API. Am I doing it wrong?

1 Answer 1

1

First you build client with needed parameters, then you call proper methods. E.g. getStage:

$client = new ApiGatewayClient({
   'credentials' => [
        // This is optional, as AWS SDK will take it directly from _SERVER superglobal
        'key' => $_SERVER['AWS_ACCESS_KEY_ID'],
        'secret' => $_SERVER['AWS_SECRET_ACCESS_KEY'],
   ],
   ...
});

$response = $client->getStage([
    'restApiId' => 'api-id',
    'stageName' => 'execute-api',
]);

$body = json_decode($response->get('Body'), true);

echo $body['cacheClusterStatus'];

Sign up to request clarification or add additional context in comments.

2 Comments

Hey @Justinas and thanks for your reply! Tried like you proposed, and edited my post a bit because there are not a lot of characters allowed for commenting. Could you please check my original post for more details?
@Clark So your message clearly states that use arn:aws:iam::804737862755:user/staging-api-s3-assets does not have enough permissions. So fix that on your own.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.