-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New distributed map construct from internet
Working with thawing and copying
- Loading branch information
1 parent
35af4c2
commit 8a3d9d2
Showing
11 changed files
with
377 additions
and
109 deletions.
There are no files selected for viewing
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
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
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
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
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
11 changes: 11 additions & 0 deletions
11
packages/aws-copy-out-sharer/src/copy-out-state-machine-input.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export type CopyOutStateMachineInput = { | ||
maxItemsPerBatch: number; | ||
requiredRegion: string; | ||
|
||
sourceFilesCsvBucket: string; | ||
sourceFilesCsvKey: string; | ||
|
||
destinationKey: string; | ||
}; | ||
|
||
export type CopyOutStateMachineInputKeys = keyof CopyOutStateMachineInput; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { Construct } from "constructs"; | ||
import { JsonPath } from "aws-cdk-lib/aws-stepfunctions"; | ||
import { S3CsvDistributedMap } from "./s3-csv-distributed-map"; | ||
import { RcloneRunTaskConstruct } from "./rclone-run-task-construct"; | ||
import { IVpc, SubnetType } from "aws-cdk-lib/aws-ec2"; | ||
import { Cluster } from "aws-cdk-lib/aws-ecs"; | ||
|
||
type Props = { | ||
vpc: IVpc; | ||
vpcSubnetSelection: SubnetType; | ||
}; | ||
|
||
export class RcloneMapConstruct extends Construct { | ||
public readonly distributedMap: S3CsvDistributedMap; | ||
|
||
constructor(scope: Construct, id: string, props: Props) { | ||
super(scope, id); | ||
|
||
const cluster = new Cluster(this, "FargateCluster", { | ||
vpc: props.vpc, | ||
enableFargateCapacityProviders: true, | ||
}); | ||
|
||
const rcloneRunTask = new RcloneRunTaskConstruct( | ||
this, | ||
"RcloneFargateTask", | ||
{ | ||
fargateCluster: cluster, | ||
vpcSubnetSelection: props.vpcSubnetSelection, | ||
}, | ||
).ecsRunTask; | ||
|
||
// our task is an idempotent copy operation so we can retry if we happen to get killed | ||
// (possible given we are using Spot fargate) | ||
rcloneRunTask.addRetry({ | ||
errors: ["States.TaskFailed"], | ||
maxAttempts: 3, | ||
}); | ||
|
||
// these names are internal only - but we pull out as a const to make sure | ||
// they are consistent | ||
const bucketColumnName = "b"; | ||
const keyColumnName = "k"; | ||
|
||
// { | ||
// "BatchInput": { | ||
// "rcloneDestination": "s3:cpg-cardiac-flagship-transfer/optionalpath" | ||
// }, | ||
// "Items": [ | ||
// { | ||
// "rcloneSource": "s3:bucket/1.fastq.gz" | ||
// }, | ||
// { | ||
// "rcloneSource": "s3:bucket/2.fastq.gz" | ||
// }, | ||
// } | ||
|
||
this.distributedMap = new S3CsvDistributedMap(this, "RcloneMap", { | ||
toleratedFailurePercentage: 25, | ||
itemReaderCsvHeaders: [bucketColumnName, keyColumnName], | ||
itemReader: { | ||
"Bucket.$": "$.sourceFilesCsvBucket", | ||
"Key.$": "$.sourceFilesCsvKey", | ||
}, | ||
itemSelector: { | ||
"rcloneSource.$": JsonPath.format( | ||
// note: this is not an s3:// URL, it is the peculiar syntax used by rclone | ||
"s3:{}/{}", | ||
JsonPath.stringAt(`$$.Map.Item.Value.${bucketColumnName}`), | ||
JsonPath.stringAt(`$$.Map.Item.Value.${keyColumnName}`), | ||
), | ||
}, | ||
batchInput: { | ||
"rcloneDestination.$": JsonPath.format( | ||
"s3:{}/{}", | ||
JsonPath.stringAt(`$.destinationBucket`), | ||
JsonPath.stringAt("$.destinationKey"), | ||
), | ||
}, | ||
iterator: rcloneRunTask, | ||
resultWriter: { | ||
"Bucket.$": "$.sourceFilesCsvBucket", | ||
"Prefix.$": JsonPath.format( | ||
"{}-results", | ||
JsonPath.stringAt("$.sourceFilesCsvKey"), | ||
), | ||
}, | ||
}); | ||
} | ||
} |
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
Oops, something went wrong.