Skip to content

Commit 383e417

Browse files
authored
feat(export): async, multi-service export (#1042)
* feat(export): new infrastructure for multi-service export * feat(export): set up multi-service export capabilities At this time the behavior should be the same, but there is an additional layer acting like a state machine to schedule the work, determine if it's finished, and notify the user if it is. * chore: fix some test mocks * chore: init queue handler remove dev fxa secret env vars (they don't exist) * chore: add dynamodb permissions * fix: re-throw unhandled error for sqs poller * chore(temp): add dev data * fix(export): use attribute substitution for reserved keywords in DynamoDB feat(terraform): Add new method for subscribing SQS to multiple SNS Need to be able to update the SQS access policy to allow two ARNs; creating subscriptions with existing method results with the policy being chosen randomly since only one can be applied to a queue. Since we are already using the wrapped helper stacks, just make a new one. Alternatively just write it all manually. * feat(export): export for annotations and shareable-lists pulling out shared code into package * feat(export): consolidate on using shared package * fix: set AWS_REGION variable * chore: initialize background tasks * fix(export): shareable-lists queue env var name * fix(export): shareable-list source in event bridge rule * fix(export): add s3 bucket perms for shareable-lists * fix: fix-mismatches * chore: remove dev data * fix(export): remove illegal char from dynamo attribute * fix: re-request dynamo item with consistency * fix: isComplete array iterator * chore: lint * fix(test): fix test command and wrong env var
1 parent 4502819 commit 383e417

File tree

76 files changed

+3628
-953
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+3628
-953
lines changed

.docker/aws-resources/account-data-deleter.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ set -x
33

44
SQS=(
55
pocket-account-data-delete-queue
6+
pocket-export-request-queue
67
pocket-list-export-queue
8+
pocket-annotations-export-queue
79
pocket-list-import-batch-queue
810
pocket-list-import-file-queue
911
)

.docker/aws-resources/shareable-lists-api.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
SQS=(
2+
pocket-shareablelist-export-queue
3+
)
4+
5+
for sqs_queue in "${SQS[@]}"; do
6+
awslocal sqs create-queue --queue-name "${sqs_queue}"
7+
done
8+
19
#!/bin/bash
210
set -x
311
bash "$(dirname "${BASH_SOURCE[0]}")/eventbus.sh"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
CREATE DATABASE IF NOT EXISTS `readitla_ril-tmp`;
2+
3+
USE `readitla_ril-tmp`;
4+
5+
ALTER TABLE `list`
6+
ADD CONSTRAINT `old_primary` UNIQUE (`user_id`,`item_id`)
7+
;
8+
9+
ALTER TABLE `list`
10+
DROP PRIMARY KEY
11+
;
12+
13+
-- The same schema as list, except uses expanded types for item_id and resolved_id.
14+
ALTER TABLE `list`
15+
MODIFY `item_id` bigint unsigned NOT NULL,
16+
MODIFY `resolved_id` bigint unsigned NOT NULL,
17+
ADD COLUMN `id` bigint unsigned NOT NULL AUTO_INCREMENT,
18+
ADD PRIMARY KEY (`id`);
19+

.github/workflows/aws-utils.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: AWS Utilities
2+
on:
3+
pull_request:
4+
paths:
5+
- 'packages/aws-utils/**'
6+
- 'docker-compose.yml'
7+
- 'pnpm-lock.yaml'
8+
- '.github/actions/**'
9+
- '.github/workflows/aws-utils.yml'
10+
- '.github/workflows/reuse-test-integrations.yml'
11+
push:
12+
branches:
13+
- main
14+
- dev
15+
paths:
16+
- 'packages/aws-utils/**'
17+
- 'docker-compose.yml'
18+
- 'pnpm-lock.yaml'
19+
- '.github/actions/**'
20+
- '.github/workflows/aws-utils.yml'
21+
- '.github/workflows/reuse-test-integrations.yml'
22+
jobs:
23+
test-integrations:
24+
if: github.event_name == 'pull_request'
25+
uses: ./.github/workflows/reuse-test-integrations.yml
26+
with:
27+
scope: '@pocket-tools/aws-utils'
28+
secrets: inherit

infrastructure/account-data-deleter/src/config/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ export const config = {
3737
databasePort: '3306',
3838
sqsBatchDeleteQueueName: `${prefix}-Sqs-Batch-Delete-Consumer-Queue`,
3939
listExportQueueName: `${prefix}-List-Export`,
40+
exportRequestQueueName: `${prefix}-Export-Request`,
41+
annotationsExportQueueName: `${prefix}-Annotations-Export`,
4042
listImportFileQueue: `${prefix}-List-Import-Files`,
4143
listImportBatchQueue: `${prefix}-List-Import-Batches`,
4244
databaseTz: 'US/Central',
@@ -48,6 +50,7 @@ export const config = {
4850
snsTopicName: {
4951
userEvents: `PocketEventBridge-${environment}-UserEvents`,
5052
listEvents: `PocketEventBridge-${environment}-ListEvents`,
53+
exportUpdateEvents: `PocketEventBridge-${environment}-ListExportReadyEvents`,
5154
},
5255
batchDeleteLambda: {
5356
name: 'BatchDeleteLambda',

infrastructure/account-data-deleter/src/dataDeleterApp.ts

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
dataAwsRegion,
88
sqsQueue,
99
dataAwsSnsTopic,
10+
dynamodbTable,
1011
} from '@cdktf/provider-aws';
1112
import { S3Bucket } from '@cdktf/provider-aws/lib/s3-bucket';
1213

@@ -20,10 +21,13 @@ export type DataDeleterAppConfig = {
2021
secretsManagerKmsAlias: dataAwsKmsAlias.DataAwsKmsAlias;
2122
snsTopic: dataAwsSnsTopic.DataAwsSnsTopic;
2223
batchDeleteQueue: sqsQueue.SqsQueue;
24+
exportRequestQueue: sqsQueue.SqsQueue;
25+
annotationsExportQueue: sqsQueue.SqsQueue;
2326
listExportQueue: sqsQueue.SqsQueue;
2427
listExportBucket: S3Bucket;
2528
listExportPartsPrefix: string;
2629
listExportArchivesPrefix: string;
30+
exportStateDb: dynamodbTable.DynamodbTable;
2731
importFileQueue: sqsQueue.SqsQueue;
2832
importBatchQueue: sqsQueue.SqsQueue;
2933
listImportBucket: S3Bucket;
@@ -63,6 +67,24 @@ export class DataDeleterApp extends Construct {
6367
`arn:aws:secretsmanager:${region.name}:${caller.accountId}:secret:${config.prefix}/*`,
6468
];
6569

70+
// Don't pull these secrets unless in production (they don't exist in dev)
71+
const FxaEnvVars = config.isProd
72+
? [
73+
{
74+
name: 'FXA_CLIENT_ID',
75+
valueFrom: `arn:aws:ssm:${region.name}:${caller.accountId}:parameter/Web/${config.environment}/FIREFOX_WEB_AUTH_CLIENT_ID`,
76+
},
77+
{
78+
name: 'FXA_CLIENT_SECRET',
79+
valueFrom: `arn:aws:ssm:${region.name}:${caller.accountId}:parameter/Web/${config.environment}/FIREFOX_WEB_AUTH_CLIENT_SECRET`,
80+
},
81+
{
82+
name: 'FXA_OAUTH_URL',
83+
valueFrom: `arn:aws:ssm:${region.name}:${caller.accountId}:parameter/Web/${config.environment}/FIREFOX_AUTH_OAUTH_URL`,
84+
},
85+
]
86+
: [];
87+
6688
const app = new PocketALBApplication(this, 'application', {
6789
alarms: {
6890
http5xxErrorPercentage: {
@@ -114,10 +136,22 @@ export class DataDeleterApp extends Construct {
114136
name: 'SQS_BATCH_DELETE_QUEUE_URL',
115137
value: `https://sqs.${region.name}.amazonaws.com/${caller.accountId}/${config.envVars.sqsBatchDeleteQueueName}`,
116138
},
139+
{
140+
name: 'EXPORT_REQUEST_QUEUE_URL',
141+
value: `https://sqs.${region.name}.amazonaws.com/${caller.accountId}/${config.envVars.exportRequestQueueName}`,
142+
},
143+
{
144+
name: 'EXPORT_REQUEST_STATE_TABLE',
145+
value: this.config.exportStateDb.name,
146+
},
117147
{
118148
name: 'SQS_LIST_EXPORT_QUEUE_URL',
119149
value: `https://sqs.${region.name}.amazonaws.com/${caller.accountId}/${config.envVars.listExportQueueName}`,
120150
},
151+
{
152+
name: 'SQS_ANNOTATIONS_EXPORT_QUEUE_URL',
153+
value: `https://sqs.${region.name}.amazonaws.com/${caller.accountId}/${config.envVars.annotationsExportQueueName}`,
154+
},
121155
{
122156
name: 'SQS_IMPORT_BATCH_QUEUE_URL',
123157
value: this.config.importBatchQueue.url,
@@ -217,18 +251,7 @@ export class DataDeleterApp extends Construct {
217251
name: 'EXPORT_SIGNEDURL_USER_SECRET_KEY',
218252
valueFrom: `arn:aws:secretsmanager:${region.name}:${caller.accountId}:secret:${config.name}/${config.environment}/EXPORT_USER_CREDS:secretAccessKey::`,
219253
},
220-
{
221-
name: 'FXA_CLIENT_ID',
222-
valueFrom: `arn:aws:ssm:${region.name}:${caller.accountId}:parameter/Web/${config.environment}/FIREFOX_WEB_AUTH_CLIENT_ID`,
223-
},
224-
{
225-
name: 'FXA_CLIENT_SECRET',
226-
valueFrom: `arn:aws:ssm:${region.name}:${caller.accountId}:parameter/Web/${config.environment}/FIREFOX_WEB_AUTH_CLIENT_SECRET`,
227-
},
228-
{
229-
name: 'FXA_OAUTH_URL',
230-
valueFrom: `arn:aws:ssm:${region.name}:${caller.accountId}:parameter/Web/${config.environment}/FIREFOX_AUTH_OAUTH_URL`,
231-
},
254+
...FxaEnvVars,
232255
],
233256
},
234257
],
@@ -276,8 +299,10 @@ export class DataDeleterApp extends Construct {
276299
],
277300
resources: [
278301
this.config.batchDeleteQueue.arn,
279-
this.config.listExportQueue.arn,
280302
this.config.importFileQueue.arn,
303+
this.config.listExportQueue.arn,
304+
this.config.exportRequestQueue.arn,
305+
this.config.annotationsExportQueue.arn,
281306
],
282307
effect: 'Allow',
283308
},
@@ -312,6 +337,19 @@ export class DataDeleterApp extends Construct {
312337
],
313338
effect: 'Allow',
314339
},
340+
// DynamoDB Status
341+
{
342+
actions: [
343+
'dynamodb:DescribeTable',
344+
'dynamodb:Get*',
345+
'dynamodb:UpdateItem',
346+
],
347+
resources: [
348+
this.config.exportStateDb.arn,
349+
`${this.config.exportStateDb.arn}/*`,
350+
],
351+
effect: 'Allow',
352+
},
315353
],
316354
taskExecutionDefaultAttachmentArn:
317355
'arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy',

0 commit comments

Comments
 (0)