AWS JS SDK(第3页)ERR_NAME_NOT_RESOLVED

时间:2016-09-19 21:07:21

标签: amazon-s3

我对AWS的AWS SDK参考其S3利用率感到困惑。以下是我的代码:

smalldict["8"] = "hello"

bigdict = {}
for i in range(10000):
    bigdict[str(i*100)] = str(i*4123)
bigdict["8000"] = "hello"

timetotal = 0
totalin = 0
totalget = 0
key = "hello"
found= 0
notfound = 0

ddo = bigdict # change to smalldict for small dict gets
print 'doing in'
for r in range(12):
    start = time.time()
    a = r % 2
    for i in range(10000000):
        if a == 0:
            if key in ddo:
                foo = ddo[key]
            else:
                foo = "nooo"
        else:
            if 'yo' in ddo:
                foo = ddo['yo']
            else:
                foo = "nooo"
    timetotal = timetotal + (time.time() - start)

totalin = timetotal / 12.0 

print 'switching to get'
timetotal = 0
for r in range(12):
    start = time.time()
    a = r % 2
    for i in range(10000000):
        if a == 0:
            foo = ddo.get(key,None)
            if foo is not None:
                # yaaay
                pass
            else:
                foo = "nooo"
        else:
            foo = ddo.get('yo',None)
            if foo is not None:
                #yaaay
                pass
            else:
                foo = "oooo"
    timetotal = timetotal + (time.time() - start)

totalget = timetotal / 12

print "total time for IN: ", totalin
print 'total time for GET: ', totalget

这会产生错误 net :: ERR_NAME_NOT_RESOLVED 。它将要发生的端点类似于 https://bucketName.undefined.us-east-1.amazonaws.com/

显然,由于未定义在URL中,因此无法解决;然而,这甚至看起来不像s3端点!它应遵循 https://s3.amazonaws.com/bucketName/someFile.txt

之类的格式

是否还有其他人遇到过与此类似的问题,或者是否存在一些基本的错误。

STR:

  1. 从AWS下载适用于S3的SDK
  2. 使用上面发布的代码(有角度,但非常自我解释)
  3. 在控制台中查看错误。
  4. 请帮忙吗?

1 个答案:

答案 0 :(得分:2)

我在浏览器中对此进行了一些调试,发现它似乎是未定义endpointPrefix的问题。这会影响选择要使用的网址模板以及奇怪的网址。

如果我们查看aws js sdk代码的调试版本,那么就有一个区域

regionConfig.rules

用于从derivedKeys(基于您的服务/区域)查找匹配项。在我的手中,我得到了:

"eu-west-1/*", "eu-*/*", "*/*"

/后面的星号表示未定义的端点前缀。但是我们想要在regionConfig.rules中匹配的规则是:

eu-west-1/s3: "s3dash"

s3dash等同于以下模板:

"{service}-{region}.amazonaws.com"

如果服务是s3,那将会有效:

s3-eu-west-1.amazonaws.com

但是因为找不到此规则而 / 匹配到:

"{service}.{region}.amazonaws.com"

因为服务endpointPrefix未定义(这就是为什么我们首先在这条规则上结束了)你得到'undefined.eu-west-1.amazonaws.com'

如果CDN有效,我们是否建议自定义下载中存在错误?