Fork me on GitHub
#aws
<
2022-10-03
>
danm10:10:23

Does the Cognitect AWS API offer anything interacting with the EC2 instance metadata? I can't find it in the docs, but other SDKs do. We want a Clojure process to be able to read the tags of the instance it's running on, which should be exposed via instance metadata

Drew Verlee09:10:34

If you can tell me the name of the aws APi service that would respond with the ev2 metadata i can probably give you an example of getting it using the clojure api.

Dimitar Uzunov14:10:08

You can make a call to the metadata service and it responds with a json doc: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-identity-documents.html

Dimitar Uzunov14:10:44

This is useful when you want to query the tags from a process running on the instance

Dimitar Uzunov14:10:24

A more flexible that works even if your process is not on the instance is to use describe instances and you get a ton of stuff

Dimitar Uzunov14:10:13

Since originally tags were not available in the metadata service, you previously had to get the instance Id and then use it with describe instances to get get the tags; now the tags are available, but not by default - they have to be enabled

Dimitar Uzunov14:10:32

I hope this helps @U0DJ4T5U1

👀 1
danm15:10:23

Cool, ta 🙂

danm15:10:49

Yeah, there isn't really an API in the way we were originally hoping, we meant using the IMDSv2 service that runs on AWS instances. A lot of other AWS SDKs include support for getting the information out of that in a more 'language standard' way, even though it's not explicitly an AWS API. It seems that neither the java v2 SDK nor the Cognitect Clojure SDK support it, so doing an instance metadata lookup externally is our best bet. We're using an ASG, and it seems to you can't turn the ability to read tags via instance metadata on through an ASG template, only through the launch template for an explicit instance, so :man-shrugging::skin-tone-2:

Dimitar Uzunov16:10:15

Well in that case you can use the regular describe instances to get the tags, the v1 version is simple as curl to get you the instanceId

lukasz18:10:14

in some environments, (Fargate for example) metadata URL is even provided via standard environment variable - so you don't have to hardcode the standard url (I believe it can change under certain circumstances)

danm10:10:57

I found https://cljdoc.org/d/com.cognitect.aws/api/0.8.301/api/cognitect.aws.client.api, but that specifically says it's implementation-internal

lukasz15:10:17

Are there any plans to migrate aws-api internals to use Jetty 10 (or 11)? Right now it's pulling jetty-util 9.4, which conflicts with dependencies required by Jetty 10 (the webserver part)

dchelimsky15:10:34

aws-api uses the Cognitect http-client, which is where the jetty dependency comes from. There is no plan to upgrade the http-client to jetty 10, however we are working on supporting the java http-client in aws-api when you're running on java >= 11. I can't give you a solid timeline on that, but it is in progress work.

☺️ 1
1
👌 3
Daniel Jomphe15:10:49

This looks even better to me than simply upgrading jetty!

Daniel Jomphe15:10:12

When you do so, if it makes sense, please remember to document the impact of configuring with jetty vs 11's client, if you measured some.

lukasz15:10:10

@U0ENYLGTA nice, that sounds great, we're on java 11 and moving to 17 soon 👍

dchelimsky15:10:32

The feature we're introducing is more like "Bring Your Own Http Client" than "yay, java 11 client". When we roll it out, there will be a protocol that you can reify to wrap the client of your choice, with implementations for the Cognitect http-client and the java 11 client. Once that's out, you could also write your own wrapper for jetty 10 or 11, clj-http, etc, etc.

👍 1
1
dchelimsky15:10:34

aws-api uses the Cognitect http-client, which is where the jetty dependency comes from. There is no plan to upgrade the http-client to jetty 10, however we are working on supporting the java http-client in aws-api when you're running on java >= 11. I can't give you a solid timeline on that, but it is in progress work.

☺️ 1
1
👌 3