PHP aws sdk: APIGW to LAMBDA deployment issue - php

The setup I want to build is 1 api gateway(1 stage/1 route) that routes everything to a lambda function.
When I set it up manually(in aws online console) everything works out fine - I use the creation wizard and everything works perfectly, and the requests are routed & executed correctly.
However if I try replicating this with AWS SDK (PHP) I get API_CONFIGURATION_ERROR (Internal Server Error 500) in the API logs.
This is the quick create setup(as per aws documenation: https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-apigatewayv2-2018-11-29.html#createapi )
$client->createApi([
"ProtocolType"=>"HTTP",
"Name"=>"myAPI",
"CredentialsArn"=>"ARN of credential", // allow APIGW to access Lambda
"RouteKey"=>"ANY /myLambda", // creates route
"Target"=>"ARN of lambda" // creates integration
]);
The creation is successful and it creates the API GW pointing to the Lambda, however it does not create a trigger in the Lambda for APIGW (the wizard does create this).
I checked the error here: https://docs.aws.amazon.com/apigateway/latest/developerguide/supported-gateway-response-types.html - but none of the cases seem to match my case.
Even if I try to create the trigger myself the error remains the same!
What am I missing? I tried to look at the various structures of the 2 gateways and could not find any meaningful differences (Api, Routes, Integration, Stages)

Related

Shopify: There’s no page at this address Check the URL and try again, or use the search bar to find what you need

I’m new to Shopify App development. I’ve developed an app using a php template provided by shopify. It’s using Laravel & React. It’s https://github.com/Shopify/shopify-app-template-php/tree/cli_three
When I execute npm run dev, the app is running in the development store.
Then, I deployed my app on the AWS server using one domain (e.g: sub.mydomain.com).
Before deployment:
I have build the frontend using: SHOPIFY_API_KEY=MY_API_KEY npm run build
I’ve run composer build too.
After that, I tried to install the app. While doing so, It’s authenticating and saving the session in the database too.
But, on redirecting after authentication, it’s not working,
First, It’s giving this error on console:
Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://mystore.myshopify.com') does not match the recipient window's origin ('https://sub.mydomain.net').
And then after redirect, it’s displaying:
Along with console error:
GET https://mystore.myshopify.com/admin/apps/40aac89c4c56232219d0f1f75a1f2ae7/?hmac=68236dae6688aafd05925cf409dfff0965236542401999f8ff47decd8b942d&host=cW9kZWFuYWx5dGljcy5JKihgZnkuY29tL2FkbWlu&shop=mystore.myshopify.com&timestamp=1657698129 404
About that console error you need to add this header on top of the page in views top_level.blade.php
<?php
$domain= $shop ?? Auth::user()->name ; ; // loged-in shopify store url example.myshopify.com
header("Content-Security-Policy: frame-ancestors https://".$domain." "."https://admin.shopify.com");
?>
This will resolve the does not match the recipient window's origin error.
After that try to open the app again or you can remove the entry from db and install the app again hope that will help.

What specifically the meaning of "Error Code 403 ASN mismatch"?

I'm trying to create an application that uses the Streamtape API (https://streamtape.com/api#download-getlink) to download a video file. My application run smoothly and perfectly on local development server. However, when I deployed it to live server (AWS), I'm getting a 403 error saying "ASN mismatch / Website: AS14618 Download: AS9299".
I'm trying to figure out the cause of it but no luck. Any idea or fix? I'm using file_get_contents to get te data from JSON response and dynamically add it to link.
https://en.wikipedia.org/wiki/Autonomous_system_(Internet)
TLDR: An ASN identifies a internet network operator. IP address blocks are assigned to ASNs.
This thing seems to be complaining that you're attempting to access it from AS14618 [Amazon] when it is expecting to be accessed from AS9299 [Philippine LDT].
Either you need to get the remote provider to allow access from Amazon, or you need to keep your website inside their approved network.

Wordpress REST API Issue

I'm currently trying to wrap my head around Wordpress and its relation to the REST API. All of theses issues are only occurring in the context of plugin development. So far I had setup my endpoint and written my callback which will be executed whenever someone is sending a GET-Request to said endpoint. However, my callback is never called. This is the file which I've written so far.
/*
* Plugin Name: cola-learning
*/
if(!defined('ABSPATH')){
die;
}
if(!function_exists('add_action')){
echo 'You cant access this ressource!';
exit;
}
function PrintRESTResponse()
{
return rest_ensure_response("student");
}
function SetupREST()
{
return register_rest_route("student/v1","/view/",[
'methods' => 'GET',
'callback' => 'PrintRESTResponse'
],false);
}
add_action('rest_api_init','SetupREST');
Perhaps it might also help, if I'll give some background information about my development machine:
- OS: Windows 10
- Server: Apache Web Server (included inside XAMPP)
- Wordpress Version: 5.3.2
- PHP Version: 7.4
- Development IDE: Eclipse 2019-12 CDT ( with PHP Plugin )
From my research, everything should work fine. However, it doesnt :/ Did I miss something crucial?
Update:
WordPress REST API Routing
WordPress is having a default route for all request which are directed to the REST API ( at least if you use XAMPP with the Bitnami WordPress application module). Now, if one wants to send a request to said REST API, the person needs to use an URL with the form of ip:port/wp-json/rest_route. ip ressembles the ip address of the server which is hosting wordpress. port is the port of said server. wp-json, however, is the portion which differs an ordinary request from a request to the REST API. Everything after this portion (rest_route) is the rest route which I've defined in the above source code.
What went wrong?
My request was pointed to the wrong endpoint. Therefore I used the URL 'localhost:wpPort/wordpress/student/v1/view/'. However, the 'wp-json/' portion is missing. Therefore WordPress will search for a page that doesn't exist in the first place. Instead I should have used the URL 'localhost:wpPort/wordpress/wp-json/student/v1/view/'.
After some troubleshooting it turns out the URL being used to test was missing a part of the endpoint path.
Here is the correct path to test the newly registered endpoint.
localhost:80/wordpress/wp-json/student/v1/view/
Here's some more reading on WP Rest API endpoints:
https://developer.wordpress.org/rest-api/extending-the-rest-api/routes-and-endpoints/

Testlink integration with redmine (interface:rest) is not working

We have Redmine & Testlink hosted on 2 different servers on Amazon Cloud.
I used below methods / workarounds to establish a connection between these two, however I am getting "Something is preventing to connect to bug tracking system, it will create performance issue..." on Execute Test page of testlink.
Made below configuration in Issue Tracker Management under
Redmine(interface:rest)
<issuetracker>
<apikey>3fe68920f3cf</apikey>
<uribase>https://odessa.sharred.net</uribase>
<uriview>https://odessa.sharred.net/redmine/CM/issues/</uriview> <!-- for Redmine 1.x add show/ -->
<projectidentifier>Common</projectidentifier>
</issuetracker>
Enabled API from redmine.
Made settings in C:\xampp\htdocs\testlink\third_party\redmine-php-api\lib\redmine-rest-api.php for curl_setopt() to allow to use HTTPS.
Tried giving Redmine Base URL using IP ADDRESS instead of Host name.
Do not see any relevant logs in testlink's events section.
Added entry of redmine in config.inc.php with $g_interface_bugs='REDMINE';
Also observed that URL given in URIBASE is opening in web browser with parameter passed as key i.e. https://odessa.sharred.net?key=3fe68920f3cf
is accessible from testlink server.
Any insight / solution on this issue will be great help.
Your configuration should look something like this.
<issuetracker>
<apikey>3fe68920f3cf</apikey>
<uribase>https://ServerIP/redmine</uribase>
<uriview>https://ServerIP/redmine/issues/</uriview>
<projectidentifier>CM</projectidentifier>
</issuetracker>
I also had trouble and just got it working now.
If you still have issue goto http://TLServerIP/testlink/lib/events/eventviewer.php and check the error
Similarly you can go to //redmineinstalldir/apps/redmine/htdocs/log/production.log to see what error you are getting after you click test connection on testlink

Twitter OAuth failing to work (PHP)

I have the TwitterOAuth class and demonstration running on a local development server and I cannot get it to authorize. I have entered the new CONSUMER_KEY and CONSUMER_SECRET in the config.php. I have also synced the server time to NTP. I get the error message: 'Could not connect to Twitter. Refresh the page or try again later.'
var_dump($connection->http_code);
results:
int 0
ANY help or advise would be appreciated.
I am running PHP 5.3
When I try to ping the api server I can't.
C:\Users\Owner>ping api.twitter.com
Ping request could not find host api.twitter.com. Please check the name and try
again.
could this be the problem ?
I had some issues with this process as well. I don't exactly recall what resolved this error, but I followed This Tutorial (albeit a bit out of date) and made sure I explicitly set the callback URL in the twitter panel for my app. Also, and I believe this one also caused the int 0 return for me, make sure that if you are going with a hosting provider they allow CURL requests.
step 1: https://apps.twitter.com/app or go to your app setting
step 2: Unchecked the (Enable Callback Locking (It is recommended to enable callback locking to ensure apps cannot overwrite the callback url)) This box..
save and exit and check..
ThankYou..!

Categories