Last active
October 26, 2021 13:44
-
-
Save flochaz/6a9e27155c8df5d6dd6448a2a7ebbd87 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function flywayServiceLambda = new Function( | |
this, | |
"runner", | |
FunctionProps.builder() | |
.environment( | |
Map.of( | |
"S3_BUCKET", migrationFilesBucket.getBucketName(), | |
"DB_CONNECTION_STRING", String.format("jdbc:mysql://{}/{}", options.databaseInstance.getDbInstanceEndpointAddress(), options.getDatabaseName()), | |
"DB_SECRET", options.databaseInstance.getSecret().getSecretFullArn())) | |
.runtime(Runtime.JAVA_11) | |
.code( | |
Code.fromAsset( | |
"../../FlywayLambdaService/", | |
AssetOptions.builder() | |
.bundling(builderOptions) | |
.build())) | |
.timeout(Duration.minutes(15)) | |
.memorySize(2048) | |
.handler("com.geekoosh.flyway.FlywayHandler::handleRequest") | |
.vpc(options.vpc) | |
.securityGroups(options.databaseInstance.getConnections().getSecurityGroups()) | |
.build()); | |
// Let Flyway Lambda get DB creds | |
options.databaseInstance.getSecret().grantRead(flywayServiceLambda); | |
// Let Flyway Lambda access the DB | |
options.databaseInstance.getConnections().allowDefaultPortInternally(); | |
// Let Flyway Lambda access the migration files bucket | |
migrationFilesBucket.grantRead(flywayServiceLambda); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment