是否可以使用AWS Data Pipeline将RDS数据库转储到S3?

时间:2017-05-15 23:30:57

标签: amazon-web-services amazon-s3 amazon-cloudformation rds amazon-data-pipeline

基本上我想使用AWS Data Pipeline将我的RDS数据库pg_dump转换为S3,

我不是百分之百确定如果可能的话我到了SqlDataNode想要selectQuery的阶段,我想知道该怎么做。

到目前为止,我的模板如下:

AWSTemplateFormatVersion: "2010-05-15"

Description: RDS to S3 Dump

Parameters:
  RDSInstanceID:
    Description: "Instance ID of RDS to Dump from"
  DatabaseName:
    Description: "Name of the Database to Dump"
    Type: String
  Username:
    Description: "Database Username"
    Type: String
  Password:
    Description: "Database password"
    Type: String
    NoEcho: true

RDSToS3Dump:
  Type: "AWS::DataPipeline::Pipeline"
  Properties:
    Name: "RDSToS3Dump"
    Description: "Pipeline to backup RDS data to S3"
    Activate: true
    ParameterObjects:
      -
        name: "SourceRDSTable"
        type: "SqlDataNode"
        Database: !Ref DatabaseName
      -
        name: !Ref DatabaseName
        type: "RdsDatabase"
        databaseName: !Ref DatabaseName
        username: !Ref Username
        password: !Ref Password
        rdsInstanceId: !Ref RDSInstanceID
      -
        name: "S3OutputLocation"
        type: "S3DataNode"
        filePath: #TODO: S3 Bucket here parameterized? Will actually need to create one.
      -
        name: "RDStoS3CopyActivity"
        type: "CopyActivity"
        input: "SourceRDSTable"
        output: "S3OutputLocation"
        #TODO: do we need a runsOn?

2 个答案:

答案 0 :(得分:3)

如另一个答案中所述, AWS Data Pipeline 仅允许您转储表而不是整个数据库。如果您真的想使用pg_dump使用AWS CloudFormation将数据库的全部内容转储到S3,则可以 使用Lambda-backed custom resources。沿着那条路走下去,你将不得不写一个Lambda函数:

  • 连接到数据库
  • 使用pg_dump
  • 转储您的数据库
  • 将其上传到S3

答案 1 :(得分:1)

使用数据管道我相信你只能像pg_dump一样转储表而不是整个数据库。

您是否查看了文档,因为selectQuery只需要一个SQL语句来表示您要转储的内容,即“select * from mytable”?也许这有帮助。 http://docs.aws.amazon.com/datapipeline/latest/DeveloperGuide/dp-object-sqldatanode.html

  -
    name: "SourceRDSTable"
    type: "SqlDataNode"
    Database: !Ref DatabaseName
    table: "mytable"
    selectQuery: "select * from #{table}"