You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何配置Flyway的flyway.locations参数以指定S3桶中的SQL脚本

Configuring Flyway locations for S3-Stored Migration Scripts

Great question! Setting up Flyway to pull migration scripts directly from an S3 bucket is totally doable—here's a step-by-step breakdown to get it working smoothly:

1. Add Required Dependencies

Flyway’s S3 support lives in a dedicated module, so you’ll need to include it in your project (if using build tools like Maven/Gradle) or ensure it’s on your classpath if running Flyway CLI:

Maven

<dependency>
    <groupId>org.flywaydb</groupId>
    <artifactId>flyway-aws-s3</artifactId>
    <version>9.22.3</version> <!-- Use the latest stable version -->
</dependency>

Gradle

implementation 'org.flywaydb:flyway-aws-s3:9.22.3'

If using the Flyway CLI, make sure you’ve downloaded the distribution that includes AWS support (or manually add the JAR to your classpath).

2. Configure AWS Credentials

Flyway uses the standard AWS credential chain to authenticate with S3, so you can set this up any of these ways:

  • Local development: Use the ~/.aws/credentials file or set the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables.
  • Cloud environments (EC2/EKS/ECS): Attach an IAM role with s3:GetObject permissions for your target bucket and path.
  • Docker/Kubernetes: Inject credentials via secrets or use IAM roles for service accounts (IRSA).

Just ensure the authenticated entity has permission to read objects from your S3 bucket’s migration script path.

3. Set the flyway.locations Parameter

Use the s3:// URL scheme to point directly to your bucket and script directory. The format is:

flyway.locations=s3://<your-bucket-name>/<path-to-migration-scripts>

Example Configurations

  • Command line:
    flyway -locations=s3://my-flyway-migrations/prod/sql migrate
    
  • Flyway config file (flyway.conf):
    flyway.locations=s3://my-flyway-migrations/prod/sql
    
  • Maven plugin:
    <plugin>
        <groupId>org.flywaydb</groupId>
        <artifactId>flyway-maven-plugin</artifactId>
        <version>9.22.3</version>
        <configuration>
            <locations>
                <location>s3://my-flyway-migrations/prod/sql</location>
            </locations>
            <!-- Add your database connection details here -->
        </configuration>
    </plugin>
    

Key Notes

  • Flyway will recursively scan all subdirectories under the specified S3 path for migration scripts (following the standard V__<description>.sql naming convention).
  • You don’t need a trailing slash at the end of the S3 path—Flyway handles both formats equally well.
  • If you’re using Flyway Teams/Enterprise, you can leverage additional features like S3 versioning support or path-based filtering, but the basic setup above works for Community Edition too.

内容的提问来源于stack exchange,提问作者AkshayBadri

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 09:00:51