I use a javascript in the workers in Cloudflare SaaS account that i am trying out for a POC.I create a request response object and am passing it to the public ip of my ec2-instance.
In order to receive it i have enabled all traffic on my ec2-instance.
Still i am getting a 502 error.Though i can make the same call from the postman installed on my PC,
but then how do i send data to the ec2-instance.The reason I ask is because this is a production code that was working and I am just making some changes to the code and for testing,using my ec2-instance.
but being on a trial license i am unable to register domain as it involves cost.
Isn’t there any other way to get my script in worker to connect to the ec2-instance?i just need to send the data and check the json structure.
You need a domain name pointing to the EC2 instance to be able to send requests from a Worker. You can register a .xyz domain for $1 for the first year.
If you absolutely cannot afford to spend $1 on a domain, you have to option of getting a .eu.org domain for free here.
You can’t create a DNS entry in Cloudflare Zero Trust. Not sure what it is you tried, but you need a proper domain added to your Cloudflare account. It does not matter whether it is a free .eu.org, a paid .xyz or something else.
What you’re doing is creating a DNS override for clients connected to your Zero Trust organization. Workers do not connect through ZT so it will not work. Like I already said, you need to get a proper domain and create a DNS record. It is the only way.
Created a domain in AWS and have successfully added it under websites in Cloudflare and am even able to access an application hosted on an AWS ec2 using the DNS mapping.
However even now when i call an api on another ec2-instance from inside the worker javascript it still gives a 502 gateway.I did also add the dns of this ec2-instance to the domain and i am able to perform a get to it using the domain from my browser.However the call from the worker script to the api on the ec2-instance gives a 502 bad gateway.
Am i missing some configuration here?
You can only send requests to non-standard ports if the Worker runs on the same domain as the URL you are trying to fetch. Therefore, if your Worker runs on mytestingdomain.org/*, you must create a DNS record on e.g. origin.mytestingdomain.org pointing to your EC2 instance. You can then call fetch('https://origin.mytestingdomain.org:3000') in the Worker.
I had also made the call without providing the port https://example.com/myapi/v1/http/myurl.
The url on to which this worker will send data is provided by the user to whom the worker is delivered as a product.In this case too i have pointed the domain to the url of the instance to which the worker sends this request.So the code ideally would take the url provided by the user in the settings—>variables—> given here.I hope you can understand whta i am trying to convey.
However in the production sense also where this worker was earlier working the domain on which the worker runs and the place to where the worker sends its data is in a different domain.
I have as of now created the DNS record in the Cloudflare websites—>DNS settings.Added two entries