Skip to content

Format s3 key#432

Open
lindseydew wants to merge 4 commits into
mainfrom
ld/format-s3-key
Open

Format s3 key#432
lindseydew wants to merge 4 commits into
mainfrom
ld/format-s3-key

Conversation

@lindseydew

@lindseydew lindseydew commented Aug 11, 2025

Copy link
Copy Markdown
Contributor

What does this change?

This formats the externalId to remove hyphens and spaces before we store it in s3

How to test

How can we measure success?

Have we considered potential risks?

Images

Accessibility

@lindseydew lindseydew changed the title Ld/format s3 key Format s3 key Aug 12, 2025
@lindseydew
lindseydew marked this pull request as ready for review August 12, 2025 09:15
@lindseydew
lindseydew requested a review from a team as a code owner August 12, 2025 09:15
@github-actions

github-actions Bot commented Aug 12, 2025

Copy link
Copy Markdown

Base automatically changed from ld/ld/read-s3-key to main August 13, 2025 09:04
const hasExternalId = externalId && externalId.trim().length > 0;
const objectKey = hasExternalId
? `${externalId}.json`
? formatS3Key(externalId)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. Should the formatting be fingerpost-specific or apply to all items going via S3? If the latter, should we add this to the poller lambdas too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good thought. Do we store the original id anywhere with the poller lambdas?

I felt like doing some manipulation here was safe because we have the externalId in the database to cross reference.

Whereas with the poller lambda I don't know whether we might not want to risk any additional manipulation? Though, I also think it's nicer to store the records in this way.

@andrew-nowak do you have any thoughts?

Comment thread scripts/start
startDockerContainers
# run all three, and terminate together when the user presses `ctrl+c`: https://stackoverflow.com/a/52033580
(trap 'kill 0' SIGINT; startIngestionLambda & startPlayApp & wait)
(trap 'kill 0' SIGINT; startQueueingLambda & startIngestionLambda & startPlayApp & wait)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤩

Comment on lines +5 to +17
const externalId = 'test-external-id';
const expectedKey = 'test-external-id.json';
expect(formatS3Key(externalId)).toBe(expectedKey);
});
it('should replace spaces with a hyphen', () => {
const externalId = 'test external id';
const expectedKey = 'test-external-id.json';
expect(formatS3Key(externalId)).toBe(expectedKey);
});
it('should replace forward slashes with a hyphen', () => {
const externalId = 'test/external/id';
const expectedKey = 'test-external-id.json';
expect(formatS3Key(externalId)).toBe(expectedKey);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this run the risk that some stories might overwrite each other in S3? if we had 3 files arrive with each of these external ids, then we'd be left with only the most recent, even though they've each got different ids. (Hopefully actually we still have all 3, but only as versions of object with the same key).
Do we have a concrete problem with the spaced or slashed keys? Maybe we run the id through a url encoder instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main thing with the spaced and slashed keys is we end up with a lot of documents with the key name as 0.json when the rest of the external id is stored as prefixes, which I was finding a bit confusing when I was trying to compare inputs.

Though yeah, I do get that doing our own manipulation could have some risks when we want to ensure the key is the identifier.

What would be the benefit of a URLEncoder instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you both think? A problem worth addressing or prefer to leave as is?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants