我使用S3来托管一个将使用HTML5 pushStates的javascript应用程序.问题是如果用户为任何URL添加书签,它将无法解析为任何内容.我需要的是能够获取所有URL请求并在我的S3存储桶中提供root index.html,而不仅仅是执行完全重定向.然后我的javascript应用程序可以解析URL并提供正确的页面.
有没有办法告诉S3为所有URL请求提供index.html而不是重定向?这与设置apache以通过提供单个index.html来处理所有传入请求类似,如下例所示:https://stackoverflow.com/a/10647521/1762614.我真的想避免运行Web服务器来处理这些路由.从S3做一切非常有吸引力.
我有一个无服务器服务,在 serverless.yml 文件中使用以下配置运行:
service: tableau-export-rest
custom:
dev:
tableauBookmarksBucket: tmt-${self:provider.stage}-tableau-bookmarks
qa:
tableauBookmarksBucket: tmt-${self:provider.stage}-tableau-bookmarks
prod:
tableauBookmarksBucket: tmt-${self:provider.stage}-tableau-bookmarks
provider:
name: aws
runtime: nodejs12.x
region: eu-west-1
stage: ${opt:stage, 'dev'}
timeout: 900
memorySize: 3008
environment:
TABLEAU_BOOKMARKS_BUCKET: ${self:custom.${self:provider.stage}.tableauBookmarksBucket}
iamRoleStatements:
- Effect: Allow
Action:
- s3:PutObject
- s3:GetObject
- s3:ListBucket
Resource: "arn:aws:s3:::${self:custom.${self:provider.stage}.tableauBookmarksBucket}/*"
- Effect: Allow
Action:
- lambda:InvokeFunction
Resource: "arn:aws:lambda:*"
functions:
saveBookmark:
handler: index.saveBookmark
timeout: 30
events:
- http:
path: /save-bookmark
method: post
cors:
origin: '*'
Run Code Online (Sandbox Code Playgroud)
该saveBookmark函数看起来像这样:
const params = {
Bucket: process.env.TABLEAU_BOOKMARKS_BUCKET,
Key: 'ABC123' …Run Code Online (Sandbox Code Playgroud) 我有一个 android gradle 构建,它在四个不同的服务器上查找依赖项。
现在构建最多需要两分钟,因为每次构建都会检查这些依赖项。发生这种情况可能是因为其中一个存储库为大多数依赖项返回了错误。
我的 gradle 文件中有以下来源:
repositories {
maven { url 'http://jenkins.local:8081/nexus/content/groups/public/' }
mavenCentral()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/'}
maven {url "https://repo.commonsware.com.s3.amazonaws.com"}
}
Run Code Online (Sandbox Code Playgroud)
第一个条目是一个代理,它应该在第一次请求之后缓存所有工件。这是依赖列表的一部分:
编译'com.android.support:support-v4:19.+'
compile 'com.squareup.picasso:picasso:2.2.+'
compile 'com.commonsware.cwac:merge:1.0.1'
compile files('libs/crittercism_v4_3_0_sdkonly.jar')
testCompile 'junit:junit:4.10'
testCompile 'org.robolectric:robolectric:2.3-SNAPSHOT'
testCompile 'com.squareup:fest-android:1.0.+'
testCompile 'org.mockito:mockito-all:1.9.5'
instrumentTestCompile 'junit:junit:4.10'
instrumentTestCompile 'org.robolectric:robolectric:2.3-SNAPSHOT'
instrumentTestCompile 'com.squareup:fest-android:1.0.+'
instrumentTestCompile 'org.mockito:mockito-all:1.9.5'
Run Code Online (Sandbox Code Playgroud)
现在,在运行 gradle 时,我得到以下输出(又是一个快照):
Failed to get resource: GET. [HTTP HTTP/1.1 403 Forbidden: https://repo.commonsware.com.s3.amazonaws.com/de/greenrobot/greendao/]
Failed to get resource: GET. [HTTP HTTP/1.1 403 Forbidden: https://repo.commonsware.com.s3.amazonaws.com/com/android/support/support-v4/maven-metadata.xml]
Failed to get resource: GET. [HTTP HTTP/1.1 403 Forbidden: …Run Code Online (Sandbox Code Playgroud) 我已使用本教程将我的 S3 存储桶设置为仅接受来自特定 IP 地址的请求。但即使这些 IP 被允许这样做GetObject,对于任何丢失的文件,它们也会收到 403 错误,而不是 404。
我更新的存储桶策略是(使用虚构的 IP 地址):
{
"Version": "2012-10-17",
"Id": "S3PolicyId1",
"Statement": [
{
"Sid": "IPDeny",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::www.bucketname.com/*",
"Condition": {
"NotIpAddress": {
"aws:SourceIp": [
"100.100.100.0/22",
"101.101.101.0/22"
]
}
}
},
{
"Sid": "ListItems",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::www.bucketname.com",
"Condition": {
"NotIpAddress": {
"aws:SourceIp": [
"100.100.100.0/22",
"101.101.101.0/22"
]
}
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
(ListBucket如 Mark B 所指出,已使用命令进行更新。)
我在这里找到了几个相关的问题(比如this和 …
我希望能够将git存储库同步到AWS S3进行备份。此外,我希望公众能够git clone备份。我的步骤是:
s3cmd mb s3://lktesting
git update-server-info
s3cmd -P sync .git/ s3://lktesting
s3cmd ws-create s3://lktesting
s3cmd ws-info s3://lktesting
Run Code Online (Sandbox Code Playgroud)
我以为这曾经有用,但现在我得到了:
git clone http://lktesting.s3-website-ap-southeast-1.amazonaws.com/
Cloning into 'lktesting.s3-website-ap-southeast-1.amazonaws.com'...
error: The requested URL returned error: 403 Forbidden (curl_result = 22, http_code = 403, sha1 = bf866b95d9517ea38e213740cead5cf1c313f5aa)
Checking connectivity... done.
Run Code Online (Sandbox Code Playgroud)
有人知道我在想什么吗?
amazon-s3 ×4
android ×1
git ×1
gradle ×1
javascript ×1
pushstate ×1
redirect ×1
routing ×1
serverless ×1