Angular AWS EC2 IP address service discovery

37 Aufrufe
Direkt zur ersten ungelesenen Nachricht

Michael Bennett

ungelesen,
26.04.2017, 01:29:1626.04.17
an Angular and AngularJS discussion
Hi everyone,

My first post here, so if I'm doing anything wrong apologies in advance.

I've been working on an Angular project and have a docker image containing it and its API (django) all one container.

This all works well when I'm running locally. The angular code builds via webpack and looks at the local IP for the API.

e.g.

localhost:8000

but when I deploy to EC2 I get a magically auto assigned IP and need my angular app on boot up to use it.

How do people do this normally? Service or API endpoint discovery seems like a core thing in a deployment like this but I think I'm going to have to do write a file into my angular 2 dist folder for NGINX to use by doing something with the AWS EC2 endpoint documented here: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-instance-addressing.html#working-with-ip-addresses 


I would do a CURL or something similar on this URL and put it into a file and then create some kind of service on my app to use this file or a sensible default for my endpoint.

Is this a good way to do it or do people have a better way?

Thanks in advance

MB

Sander Elias

ungelesen,
26.04.2017, 02:43:2326.04.17
an Angular and AngularJS discussion
Hi Michael,

Usually, this is something you arrange inside your webserver, in this case, it's Nginx I believe. And you use the AWS DNS to hook it up to a domain name. Then in your app, you can simply inspect the headers if you need it for some reason in your app itself.

Regards
Sander

Michael Bennett

ungelesen,
26.04.2017, 05:31:0726.04.17
an Angular and AngularJS discussion
Thanks sander, would you have an example of how to do this?

I'm not sure how I could get my config inside angular to use AWS DNS. The API endpoint is on the same host and the host name is dynamic and they are pretty much a standalone microapp/service so they only talk to themselves, people test on them they get disposed. I don't need to save or get state from a third party service. So I don't think AWS DNS would be suitable here. Maybe I'm wrong? 

I realise I can have a multi container service in place as another option but I still would need to configure the Angular service to use the endpoint URL somehow from the containers starting up. Plus thats overkill and costs more money on AWS. 8-)



Thanks

MB

Sander Elias

ungelesen,
26.04.2017, 07:11:2726.04.17
an Angular and AngularJS discussion
Hi Michael,

You confuse me... How are you going to open your angular app? You can't boot an app, unless you have an ip or DNS-name tied to it. You hardly can ask an app it's ip, before it's started, right? Or am I missing something?

Regards
Sander

Michael Bennett

ungelesen,
27.04.2017, 03:22:1427.04.17
an Angular and AngularJS discussion
The Services that get spun are isolated and on a per client basis. Its a simulation environment, completely standalone.

The client is given this specific IP/URL, we do this manually. That's not really important. This isn't a cluster of services using one global DNS. They are isolated instances.

When the Docker container boots up. I can query at run time the service for its IP address so it can then point any endpoint requests back to itself. I don't need DNS for this, the IP address would do or the host name (xxxx_xxx_xxx_.awsblahblah.amazon.com for example) so the angular code running in the client knows how to get back to machine its running on to get to the API. In the future this could be on a Route66 DNS address but right now its an MVP and it needs to talk to itself.

I have a solution, I just wondered if anyone else had a possible way to do it. Seems not.

Thanks for the advice

MB

Sander Elias

ungelesen,
27.04.2017, 09:39:1827.04.17
an Angular and AngularJS discussion
Hi Michael,

Well, in the angular part, you can inspect your host, and know how it's started. From there you shoul dbe able to 'calculate' the api server's address.

Regards
Sander
Allen antworten
Antwort an Autor
Weiterleiten
0 neue Nachrichten