Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Revert "feat: Multi bucket support"" #1856

Merged
merged 8 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .changeset/sharp-penguins-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
'@aws-amplify/deployed-backend-client': minor
'@aws-amplify/backend-output-schemas': minor
'@aws-amplify/backend-output-storage': minor
'@aws-amplify/backend-storage': minor
'@aws-amplify/client-config': minor
'@aws-amplify/plugin-types': minor
'@aws-amplify/backend': minor
---

support adding more than one bucket
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions packages/backend-output-schemas/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,24 +275,29 @@ export const unifiedBackendOutputSchema: z.ZodObject<{
payload: z.ZodObject<{
bucketName: z.ZodString;
storageRegion: z.ZodString;
buckets: z.ZodOptional<z.ZodString>;
}, "strip", z.ZodTypeAny, {
bucketName: string;
storageRegion: string;
buckets?: string | undefined;
}, {
bucketName: string;
storageRegion: string;
buckets?: string | undefined;
}>;
}, "strip", z.ZodTypeAny, {
version: "1";
payload: {
bucketName: string;
storageRegion: string;
buckets?: string | undefined;
};
}, {
version: "1";
payload: {
bucketName: string;
storageRegion: string;
buckets?: string | undefined;
};
}>]>>;
"AWS::Amplify::Custom": z.ZodOptional<z.ZodDiscriminatedUnion<"version", [z.ZodObject<{
Expand Down Expand Up @@ -391,6 +396,7 @@ export const unifiedBackendOutputSchema: z.ZodObject<{
payload: {
bucketName: string;
storageRegion: string;
buckets?: string | undefined;
};
} | undefined;
"AWS::Amplify::Function"?: {
Expand Down Expand Up @@ -455,6 +461,7 @@ export const unifiedBackendOutputSchema: z.ZodObject<{
payload: {
bucketName: string;
storageRegion: string;
buckets?: string | undefined;
};
} | undefined;
"AWS::Amplify::Function"?: {
Expand Down Expand Up @@ -684,24 +691,29 @@ export const versionedStorageOutputSchema: z.ZodDiscriminatedUnion<"version", [z
payload: z.ZodObject<{
bucketName: z.ZodString;
storageRegion: z.ZodString;
buckets: z.ZodOptional<z.ZodString>;
}, "strip", z.ZodTypeAny, {
bucketName: string;
storageRegion: string;
buckets?: string | undefined;
}, {
bucketName: string;
storageRegion: string;
buckets?: string | undefined;
}>;
}, "strip", z.ZodTypeAny, {
version: "1";
payload: {
bucketName: string;
storageRegion: string;
buckets?: string | undefined;
};
}, {
version: "1";
payload: {
bucketName: string;
storageRegion: string;
buckets?: string | undefined;
};
}>]>;

Expand Down
7 changes: 7 additions & 0 deletions packages/backend-output-schemas/src/storage/v1.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import { z } from 'zod';

const bucketSchema = z.object({
name: z.string(),
bucketName: z.string(),
storageRegion: z.string(),
});

export const storageOutputSchema = z.object({
version: z.literal('1'),
payload: z.object({
bucketName: z.string(),
storageRegion: z.string(),
buckets: z.string(z.array(bucketSchema)).optional(), // JSON serialized array of bucketSchema
}),
});
3 changes: 2 additions & 1 deletion packages/backend-output-storage/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { BackendOutputEntry } from '@aws-amplify/plugin-types';
import { BackendOutputStorageStrategy } from '@aws-amplify/plugin-types';
import { DeepPartial } from '@aws-amplify/plugin-types';
import * as _os from 'os';
import { PackageJsonReader } from '@aws-amplify/platform-core';
import { Stack } from 'aws-cdk-lib';
Expand Down Expand Up @@ -37,7 +38,7 @@ export type Platform = 'Mac' | 'Windows' | 'Linux' | 'Other';
export class StackMetadataBackendOutputStorageStrategy implements BackendOutputStorageStrategy<BackendOutputEntry> {
constructor(stack: Stack);
addBackendOutputEntry: (keyName: string, backendOutputEntry: BackendOutputEntry) => void;
appendToBackendOutputList: (keyName: string, backendOutputEntry: BackendOutputEntry) => void;
appendToBackendOutputList: (keyName: string, backendOutputEntry: DeepPartial<BackendOutputEntry>) => void;
}

// (No @packageDocumentation comment for this package)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ void describe('StackMetadataBackendOutputStorageStrategy', () => {
outputStorage.addBackendOutputEntry('TestStorageOutput', {
version: '1',
payload: {
something: 'special',
bucketName: 'test-bucket',
storageRegion: 'us-west-2',
},
});

const template = Template.fromStack(stack);
template.hasOutput('something', { Value: 'special' });
template.hasOutput('bucketName', { Value: 'test-bucket' });
template.templateMatches({
Metadata: {
TestStorageOutput: {
version: '1',
stackOutputs: ['something'],
stackOutputs: ['bucketName', 'storageRegion'],
},
},
});
Expand All @@ -41,7 +42,8 @@ void describe('StackMetadataBackendOutputStorageStrategy', () => {
outputStorage.addBackendOutputEntry('TestStorageOutput', {
version: '44',
payload: {
something: 'special',
bucketName: 'test-bucket',
storageRegion: 'us-west-2',
},
});

Expand All @@ -61,17 +63,19 @@ void describe('StackMetadataBackendOutputStorageStrategy', () => {
outputStorage.appendToBackendOutputList('TestStorageOutput', {
version: '1',
payload: {
something: 'special',
buckets: 'test-bucket',
},
});

const template = Template.fromStack(stack);
template.hasOutput('something', { Value: JSON.stringify(['special']) });
template.hasOutput('buckets', {
Value: JSON.stringify(['test-bucket']),
});
template.templateMatches({
Metadata: {
TestStorageOutput: {
version: '1',
stackOutputs: ['something'],
stackOutputs: ['buckets'],
},
},
});
Expand All @@ -86,57 +90,93 @@ void describe('StackMetadataBackendOutputStorageStrategy', () => {
outputStorage.appendToBackendOutputList('TestStorageOutput', {
version: '1',
payload: {
something: 'special',
buckets: JSON.stringify({
name: 'test-bucket',
bucketName: 'test-bucket',
storageRegion: 'us-west-2',
}),
},
});
outputStorage.addBackendOutputEntry('TestStorageOutput', {
version: '1',
payload: {
bucketName: 'test-bucket-two',
storageRegion: 'us-west-2',
},
});
outputStorage.appendToBackendOutputList('TestStorageOutput', {
version: '1',
payload: {
something: 'otherSpecial',
buckets: JSON.stringify({
name: 'test-bucket-two',
bucketName: 'test-bucket-two',
storageRegion: 'us-west-2',
}),
},
});
const template = Template.fromStack(stack);
template.hasOutput('something', {
Value: JSON.stringify(['special', 'otherSpecial']),
template.hasOutput('buckets', {
Value: JSON.stringify([
'{"name":"test-bucket","bucketName":"test-bucket","storageRegion":"us-west-2"}',
'{"name":"test-bucket-two","bucketName":"test-bucket-two","storageRegion":"us-west-2"}',
]),
});
template.templateMatches({
Metadata: {
TestStorageOutput: {
version: '1',
stackOutputs: ['something'],
stackOutputs: ['buckets', 'bucketName', 'storageRegion'],
},
},
});
});

void it('appends a cdk token to an existing list in stack output', () => {
void it('appends a cdk token to an existing list in stack output with two buckets', () => {
const testToken = Token.asString('testToken');
const app = new App();
const stack = new Stack(app);
const outputStorage = new StackMetadataBackendOutputStorageStrategy(
stack
);
outputStorage.addBackendOutputEntry('TestStorageOutput', {
version: '1',
payload: {
bucketName: testToken,
storageRegion: 'us-west-2',
},
});
outputStorage.appendToBackendOutputList('TestStorageOutput', {
version: '1',
payload: {
something: 'special',
buckets: JSON.stringify({
name: testToken,
bucketName: testToken,
storageRegion: 'us-west-2',
}),
},
});
outputStorage.appendToBackendOutputList('TestStorageOutput', {
version: '1',
payload: {
something: testToken,
buckets: JSON.stringify({
name: 'test-bucket-two',
bucketName: 'test-bucket-two',
storageRegion: 'us-west-2',
}),
},
});
const template = Template.fromStack(stack);
template.hasOutput('something', {
Value: JSON.stringify(['special', 'testToken']),
template.hasOutput('buckets', {
Value: JSON.stringify([
'{"name":"testToken","bucketName":"testToken","storageRegion":"us-west-2"}',
'{"name":"test-bucket-two","bucketName":"test-bucket-two","storageRegion":"us-west-2"}',
]),
});
template.templateMatches({
Metadata: {
TestStorageOutput: {
version: '1',
stackOutputs: ['something'],
stackOutputs: ['buckets', 'bucketName', 'storageRegion'],
},
},
});
Expand All @@ -151,7 +191,7 @@ void describe('StackMetadataBackendOutputStorageStrategy', () => {
outputStorage.appendToBackendOutputList('TestStorageOutput', {
version: '1',
payload: {
something: 'special',
buckets: 'test-bucket',
},
});

Expand All @@ -160,7 +200,8 @@ void describe('StackMetadataBackendOutputStorageStrategy', () => {
outputStorage.appendToBackendOutputList('TestStorageOutput', {
version: '2',
payload: {
something: 'otherSpecial',
bucketName: 'test-bucket',
storageRegion: 'us-west-2',
},
}),
{
Expand Down
Loading
Loading