-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
localhost_is_ec2() == false on ECS running in AWS Batch #24
Comments
Investigating and providing a minimal reproducible example. Running the following in AWS Batch:
shows
|
HI @ianfiske I've made a change 1e5964e to detect ECS by Reference: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/identify_ec2_instances.html |
Hi, |
Do these instances have a |
Yes. |
Could you try adding something like this to return isfile("/sys/hypervisor/uuid") &&
String(read("/sys/hypervisor/uuid",3)) == "ec2" ||
isfile("/sys/devices/virtual/dmi/id/product_uuid") &&
String(read("/sys/devices/virtual/dmi/id/product_uuid",3)) == "EC2" https://github.com/JuliaCloud/AWSCore.jl/blob/master/src/AWSCredentials.jl#L112 |
I certainly can :-) |
Let me know if it works or if you need to tweak it a bit to get it to work... |
I will let you know how I get on. |
Unfortunately the |
Some issues with a connect timeout:
So, the options seem to be:
function localhost_has_instance_profile()
result = Ref{Bool}(false)
@schedule try
info = JSON.parse(ec2_metadata("iam/info"))
result[] = haskey(info, "InstanceProfileArn")
catch e
end
sleep(0.5)
return result[]
end |
I see. Thanks for your outline. |
Perhaps we could do this diff --git a/src/AWSCredentials.jl b/src/AWSCredentials.jl
index d2eed3a..99dec55 100644
--- a/src/AWSCredentials.jl
+++ b/src/AWSCredentials.jl
@@ -11,7 +11,7 @@
export AWSCredentials,
localhost_is_lambda,
- localhost_is_ec2,
+ localhost_maybe_ec2,
aws_user_arn,
aws_account_number
@@ -75,7 +75,7 @@ function AWSCredentials()
creds = ecs_instance_credentials()
- elseif localhost_is_ec2()
+ elseif localhost_maybe_ec2()
creds = ec2_instance_credentials()
@@ -103,7 +103,7 @@ localhost_is_lambda() = haskey(ENV, "LAMBDA_TASK_ROOT")
Is Julia running on an EC2 virtual machine?
"""
-function localhost_is_ec2()
+function localhost_maybe_ec2()
if localhost_is_lambda()
return false
@@ -111,7 +111,8 @@ function localhost_is_ec2()
@static if VERSION < v"0.7.0-DEV" ? is_unix() : Sys.isunix()
return isfile("/sys/hypervisor/uuid") &&
- String(read("/sys/hypervisor/uuid",3)) == "ec2"
+ String(read("/sys/hypervisor/uuid",3)) == "ec2" ||
+ isfile("/sys/devices/virtual/dmi/id/product_uuid")
end
return false
@@ -169,8 +170,6 @@ for `key`.
function ec2_metadata(key)
- @assert localhost_is_ec2()
-
String(http_get("http://169.254.169.254/latest/meta-data/$key").body)
end
@@ -185,8 +184,6 @@ for EC2 virtual machine.
function ec2_instance_credentials()
- @assert localhost_is_ec2()
-
info = ec2_metadata("iam/info")
info = JSON.parse(info, dicttype=Dict{String,String})
|
Yes, you are right, that will solve all the problems without having to add any user package code. |
It looks like 169.254.169.254 does not respond to ping, so that's out. |
Please try this branch: #33 |
I have successfully gotten credentials (
|
Improve EC2 detection to handle new non-Xen c5 and m5 instances, See #24
Thanks for testing this @jademackay. |
@samoconnor I apologize for the long delay verifying your fix. I just tested the latest release of AWSCore, v0.3.8 both locally and in AWS Batch. Your fix is working great. A simple Thanks for the fix! |
HI @ianfiske, good to hear! Another thing to be aware of: Many of the julia AWS API functions now allow you to leave out the 1st argument |
Hi @samoconnor, Thank you for the heads up about the changes to the |
Also added check for isfile and isreadable, in case we aren't root. See issue JuliaCloud#24
104: Added check for sys_vendor file in localhost_is_ec2(), also added che… r=mattBrzezinski a=phyatt-corp …ck for isfile and isreadable, in case we aren't root Included comments for how to use Instance Metadata Service for checking a local_hostname #24 This adds support for c5 and m5 instance types without root access, and will likely work with any future ec2 instances on Nitro Hypervisor. Co-authored-by: Peter Hyatt <peter.hyatt+corp@gmail.com>
104: Added check for sys_vendor file in localhost_is_ec2 r=mattBrzezinski a=phyatt-corp …ck for isfile and isreadable, in case we aren't root Included comments for how to use Instance Metadata Service for checking a local_hostname #24 This adds support for c5 and m5 instance types without root access, and will likely work with any future ec2 instances on Nitro Hypervisor. Co-authored-by: Peter Hyatt <peter.hyatt+corp@gmail.com>
I am trying to get credentials working in jobs submitted by AWS Batch, which uses ECS under the hood. It seems like the intention of AWSCore.jl is to get creds from
aws_config()
or directly fromecs_instance_credentials()
. However, these fail becauselocalhost_is_ec2()
assertions fail:The text was updated successfully, but these errors were encountered: