Heroku Postgres:AWS s3 预签名 URL 不起作用

Pau*_*son 7 postgresql heroku amazon-s3 amazon-web-services

我已经陷入这个错误 6 个小时并且快疯了。

我已经使用 CLI 创建了一个 heroku 应用程序并成功推送了 git,但是我需要db.create_all()在应用程序工作之前使用初始化一堆表,但是我的本地主机 postgres 中有 6GB 的数据,我希望将其迁移到 heroku 来使用。

以通常的方式实例化表(create_all)将不起作用,因为索引页的表需要某些内容,因此我的表必须预先填充所述本地主机数据才能工作。

我已严格按照此处的文档进行操作,导出了 .dump 文件并将其上传到我的存储桶:https ://devcenter.heroku.com/articles/heroku-postgres-import-export#import

公共共享已启用,并且我已使用命令在 AWS CLI 中setx设置ACCESS_KEY_ID和。SECRET_ACCESS_KEY我也定了heroku config:set AWS_ACCESS_KEY_ID=matching_aws_cli_blah AWS_SECRET_ACCESS_KEY=matching_aws_cli_blah

然后使用命令aws s3 presign s3_url我复制了输出(我将添加的输出看起来与我使用的AWS文档不同https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3/presign.html

我的外观示例(随机更改了一些数字) https://mybucketname.s3.eu-west-2.amazonaws.com/mydb.dump?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=LLLLL4C7LLLLLLLNLLLQ%2FNNNNNN08%2Feu-west-2%2Fs3%2Faws4_request&X-Amz-Date=20201208T004613Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&X-Amz-Signature=ll9d80nnnnc457ea83298fdnnnn4a25b0c9ll066f54e6ff8acf42dafnnnea8877,而文档提供了一个漂亮整洁的 AWSAccessKeyId= 变量。

我只有一个存储桶,并且Block public access (bucket settings)设置为“关闭”,并且文件本身可以公开共享。对象 URL 初始化下载,包括隐身下载。

使用以下命令时(根据heroku文档)

heroku pg:backups:restore 'https://mybucketname.s3.eu-west-2.amazonaws.com/mydb.dump?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=LLLLL4C7LLLLLLLNLLLQ%2FNNNNNN08%2Feu-west-2%2Fs3%2Faws4_request&X-Amz-Date=20201208T004613Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&X-Amz-Signature=ll9d80nnnnc457ea83298fdnnnn4a25b0c9ll066f54e6ff8acf42dafnnnea8877' DATABASE_URL

我得到以下输出到终端。

Restoring... !
 !    An error occurred and the backup did not finish.
 !
 !    waiting for restore to complete
 !    pg_restore finished with errors
 !    waiting for download to complete
 !    download finished with errors
 !    please check the source URL and ensure it is publicly accessible
 !
 !    Run heroku pg:backups:info r001 for more details.
'X-Amz-Credential' is not recognized as an internal or external command,
operable program or batch file.
'X-Amz-Date' is not recognized as an internal or external command,
operable program or batch file.
'X-Amz-Expires' is not recognized as an internal or external command,
operable program or batch file.
'X-Amz-SignedHeaders' is not recognized as an internal or external command,
operable program or batch file.
'X-Amz-Signature' is not recognized as an internal or external command,
operable program or batch file.
Run Code Online (Sandbox Code Playgroud)

日志文件中显示

=== Backup r001
Database:         BACKUP
Started at:       2020-12-08 00:47:33 +0000
Finished at:      2020-12-08 00:47:34 +0000
Status:           Failed
Type:             Manual
Backup Size:      0.00B (0% compression)

=== Backup Logs
2020-12-08 00:47:34 +0000 2020/12/08 00:47:34 aborting: could not write to output stream: Expected HTTP Status 200, received: "400 Bad Request"
2020-12-08 00:47:34 +0000 pg_restore: error: could not read from input file: end of file
2020-12-08 00:47:34 +0000 waiting for restore to complete
2020-12-08 00:47:34 +0000 pg_restore finished with errors
2020-12-08 00:47:34 +0000 waiting for download to complete
2020-12-08 00:47:34 +0000 download finished with errors
2020-12-08 00:47:34 +0000 please check the source URL and ensure it is publicly accessible
Run Code Online (Sandbox Code Playgroud)

请有人指出我哪里出错了?

谢谢!

Ada*_*icz 1

诀窍是向heroku命令传递额外的引号。

它看起来像这样: