Skip to content
Draft
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
5 changes: 5 additions & 0 deletions .changeset/eighty-planes-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@aws-amplify/backend-storage': patch
---

add isDefault
6 changes: 6 additions & 0 deletions .changeset/great-apples-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@aws-amplify/backend-output-storage': patch
'@aws-amplify/backend-storage': patch
---

accumulate metadata value
9 changes: 9 additions & 0 deletions .changeset/pretty-clocks-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@aws-amplify/deployed-backend-client': patch
'@aws-amplify/backend-output-schemas': patch
'@aws-amplify/backend-output-storage': patch
'@aws-amplify/backend-storage': patch
'@aws-amplify/client-config': patch
---

add allBuckets to outputs
16 changes: 8 additions & 8 deletions package-lock.json

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

24 changes: 24 additions & 0 deletions packages/backend-output-schemas/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,26 +273,36 @@ export const unifiedBackendOutputSchema: z.ZodObject<{
"AWS::Amplify::Storage": z.ZodOptional<z.ZodDiscriminatedUnion<"version", [z.ZodObject<{
version: z.ZodLiteral<"1">;
payload: z.ZodObject<{
friendlyName: z.ZodString;
bucketName: z.ZodString;
storageRegion: z.ZodString;
allBuckets: z.ZodOptional<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodString>, "many">>;
}, "strip", z.ZodTypeAny, {
friendlyName: string;
bucketName: string;
storageRegion: string;
allBuckets?: Record<string, string>[] | undefined;
}, {
friendlyName: string;
bucketName: string;
storageRegion: string;
allBuckets?: Record<string, string>[] | undefined;
}>;
}, "strip", z.ZodTypeAny, {
version: "1";
payload: {
friendlyName: string;
bucketName: string;
storageRegion: string;
allBuckets?: Record<string, string>[] | undefined;
};
}, {
version: "1";
payload: {
friendlyName: string;
bucketName: string;
storageRegion: string;
allBuckets?: Record<string, string>[] | undefined;
};
}>]>>;
"AWS::Amplify::Custom": z.ZodOptional<z.ZodDiscriminatedUnion<"version", [z.ZodObject<{
Expand Down Expand Up @@ -389,8 +399,10 @@ export const unifiedBackendOutputSchema: z.ZodObject<{
"AWS::Amplify::Storage"?: {
version: "1";
payload: {
friendlyName: string;
bucketName: string;
storageRegion: string;
allBuckets?: Record<string, string>[] | undefined;
};
} | undefined;
"AWS::Amplify::Function"?: {
Expand Down Expand Up @@ -453,8 +465,10 @@ export const unifiedBackendOutputSchema: z.ZodObject<{
"AWS::Amplify::Storage"?: {
version: "1";
payload: {
friendlyName: string;
bucketName: string;
storageRegion: string;
allBuckets?: Record<string, string>[] | undefined;
};
} | undefined;
"AWS::Amplify::Function"?: {
Expand Down Expand Up @@ -682,26 +696,36 @@ export const versionedGraphqlOutputSchema: z.ZodDiscriminatedUnion<"version", [z
export const versionedStorageOutputSchema: z.ZodDiscriminatedUnion<"version", [z.ZodObject<{
version: z.ZodLiteral<"1">;
payload: z.ZodObject<{
friendlyName: z.ZodString;
bucketName: z.ZodString;
storageRegion: z.ZodString;
allBuckets: z.ZodOptional<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodString>, "many">>;
}, "strip", z.ZodTypeAny, {
friendlyName: string;
bucketName: string;
storageRegion: string;
allBuckets?: Record<string, string>[] | undefined;
}, {
friendlyName: string;
bucketName: string;
storageRegion: string;
allBuckets?: Record<string, string>[] | undefined;
}>;
}, "strip", z.ZodTypeAny, {
version: "1";
payload: {
friendlyName: string;
bucketName: string;
storageRegion: string;
allBuckets?: Record<string, string>[] | undefined;
};
}, {
version: "1";
payload: {
friendlyName: string;
bucketName: string;
storageRegion: string;
allBuckets?: Record<string, string>[] | undefined;
};
}>]>;

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

const bucketSchema = z.record(z.string(), z.string());

export const storageOutputSchema = z.object({
version: z.literal('1'),
payload: z.object({
friendlyName: z.string(),
bucketName: z.string(),
storageRegion: z.string(),
allBuckets: z.array(bucketSchema).optional(),
}),
});
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,19 @@ export class StackMetadataBackendOutputStorageStrategy
new CfnOutput(this.stack, key, { value });
});

const metadataValue =
this.stack.templateOptions.metadata &&
this.stack.templateOptions.metadata[keyName]
? this.stack.templateOptions.metadata[keyName]
: { stackOutputs: [] };

this.stack.addMetadata(keyName, {
...metadataValue,
version: backendOutputEntry.version,
stackOutputs: Object.keys(backendOutputEntry.payload),
stackOutputs: [
...metadataValue.stackOutputs,
...Object.keys(backendOutputEntry.payload),
],
});
};

Expand Down
2 changes: 2 additions & 0 deletions packages/backend-storage/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export type AmplifyStorageFactoryProps = Omit<AmplifyStorageProps, 'outputStorag

// @public (undocumented)
export type AmplifyStorageProps = {
friendlyName: string;
isDefault?: boolean;
name: string;
versioned?: boolean;
outputStorageStrategy?: BackendOutputStorageStrategy<StorageOutput>;
Expand Down
45 changes: 36 additions & 9 deletions packages/backend-storage/src/construct.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,22 @@ void describe('AmplifyStorage', () => {
void it('creates a bucket', () => {
const app = new App();
const stack = new Stack(app);
new AmplifyStorage(stack, 'test', { name: 'testName' });
new AmplifyStorage(stack, 'test', {
name: 'testName',
friendlyName: 'testFriendlyName',
});
const template = Template.fromStack(stack);
template.resourceCountIs('AWS::S3::Bucket', 1);
});

void it('turns versioning on if specified', () => {
const app = new App();
const stack = new Stack(app);
new AmplifyStorage(stack, 'test', { versioned: true, name: 'testName' });
new AmplifyStorage(stack, 'test', {
versioned: true,
name: 'testName',
friendlyName: 'testFriendlyName',
});
const template = Template.fromStack(stack);
template.resourceCountIs('AWS::S3::Bucket', 1);
template.hasResourceProperties('AWS::S3::Bucket', {
Expand All @@ -33,7 +40,10 @@ void describe('AmplifyStorage', () => {
void it('stores attribution data in stack', () => {
const app = new App();
const stack = new Stack(app);
new AmplifyStorage(stack, 'testAuth', { name: 'testName' });
new AmplifyStorage(stack, 'testAuth', {
name: 'testName',
friendlyName: 'testFriendlyName',
});

const template = Template.fromStack(stack);
assert.equal(
Expand All @@ -45,7 +55,10 @@ void describe('AmplifyStorage', () => {
void it('enables cors on the bucket', () => {
const app = new App();
const stack = new Stack(app);
new AmplifyStorage(stack, 'testAuth', { name: 'testName' });
new AmplifyStorage(stack, 'testAuth', {
name: 'testName',
friendlyName: 'testFriendlyName',
});

const template = Template.fromStack(stack);
template.hasResourceProperties('AWS::S3::Bucket', {
Expand All @@ -71,7 +84,10 @@ void describe('AmplifyStorage', () => {
void it('sets destroy retain policy and auto-delete objects true', () => {
const app = new App();
const stack = new Stack(app);
new AmplifyStorage(stack, 'testBucketId', { name: 'testName' });
new AmplifyStorage(stack, 'testBucketId', {
name: 'testName',
friendlyName: 'testFriendlyName',
});

const template = Template.fromStack(stack);
const buckets = template.findResources('AWS::S3::Bucket');
Expand All @@ -91,7 +107,10 @@ void describe('AmplifyStorage', () => {
void it('forces SSL', () => {
const app = new App();
const stack = new Stack(app);
new AmplifyStorage(stack, 'testBucketId', { name: 'testName' });
new AmplifyStorage(stack, 'testBucketId', {
name: 'testName',
friendlyName: 'testFriendlyName',
});

const template = Template.fromStack(stack);

Expand Down Expand Up @@ -120,8 +139,10 @@ void describe('AmplifyStorage', () => {
};

const storageConstruct = new AmplifyStorage(stack, 'test', {
friendlyName: 'testFriendlyName',
name: 'testName',
outputStorageStrategy: storageStrategy,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
outputStorageStrategy: storageStrategy as any,
});

const expectedBucketName = (
Expand All @@ -147,7 +168,10 @@ void describe('AmplifyStorage', () => {
const app = new App();
const stack = new Stack(app);

new AmplifyStorage(stack, 'test', { name: 'testName' });
new AmplifyStorage(stack, 'test', {
name: 'testName',
friendlyName: 'testFriendlyName',
});
const template = Template.fromStack(stack);
template.templateMatches({
Metadata: {
Expand All @@ -165,7 +189,10 @@ void describe('AmplifyStorage', () => {
const app = new App();
const stack = new Stack(app);

const bucket = new AmplifyStorage(stack, 'test', { name: 'testName' });
const bucket = new AmplifyStorage(stack, 'test', {
name: 'testName',
friendlyName: 'testFriendlyName',
});
bucket.resources.cfnResources.cfnBucket.accelerateConfiguration = {
accelerationStatus: 'Enabled',
};
Expand Down
22 changes: 17 additions & 5 deletions packages/backend-storage/src/construct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const storageStackType = 'storage-S3';
export type AmplifyStorageTriggerEvent = 'onDelete' | 'onUpload';

export type AmplifyStorageProps = {
friendlyName: string;
isDefault?: boolean;
/**
* Friendly name that will be used to derive the S3 Bucket name
*/
Expand Down Expand Up @@ -122,7 +124,11 @@ export class AmplifyStorage
},
};

this.storeOutput(props.outputStorageStrategy);
this.storeOutput(
props.outputStorageStrategy,
props.isDefault || false,
props.friendlyName
);

new AttributionMetadataStorage().storeAttributionMetadata(
Stack.of(this),
Expand All @@ -148,14 +154,20 @@ export class AmplifyStorage
private storeOutput = (
outputStorageStrategy: BackendOutputStorageStrategy<StorageOutput> = new StackMetadataBackendOutputStorageStrategy(
Stack.of(this)
)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
) as any,
isDefault: boolean,
friendlyName: string
): void => {
const num = isDefault ? '' : Math.floor(Math.random() * 100);
outputStorageStrategy.addBackendOutputEntry(storageOutputKey, {
version: '1',
payload: {
storageRegion: Stack.of(this).region,
bucketName: this.resources.bucket.bucketName,
},
[`storageRegion${num}`]: Stack.of(this).region,
[`bucketName${num}`]: this.resources.bucket.bucketName,
[`friendlyName${num}`]: friendlyName,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any,
});
};
}
Loading