Skip to content

(gen2-migration) generate command should handle storage overrides #14640

@iliapolo

Description

@iliapolo

Is this feature request related to a new or existing Amplify category?

No response

Is this related to another service?

No response

Describe the feature you'd like to request

In Gen1, customers can override the built-in storage resources by running amplify override storage. This creates an overrides.ts file where customers can override resource properties using the CDK. For example

import { AmplifyProjectInfo, AmplifyS3ResourceTemplate } from '@aws-amplify/cli-extensibility-helper';

export function override(resources: AmplifyS3ResourceTemplate, amplifyProjectInfo: AmplifyProjectInfo) {
  resources.s3Bucket!.versioningConfiguration = { status: 'Enabled'}
}

In Gen2, the same can be achieved by directly writing equivalent CDK code:

backend.storage.resources.cfnResources.cfnBucket.versioningConfiguration = { status: 'Enabled' };

Our code-generation should take this override.ts file into account and produce the equivalent Gen2 code.

Describe the solution you'd like

Ideally, we would transform the override.ts to look like this:

export function override(backend: Backend<any>, amplifyProjectInfo: { envName: string, projectName: string }) {
  backend.storage.resources.cfnResources.cfnBucket.versioningConfiguration = { status: 'Enabled'}
}

And then invoke this function from backend.ts:

import { override as overrideStorage } from './storage/override.ts`

const branchName = process.env.AWS_BRANCH ?? 'sandbox';
const backend = defineBackend({
  ...,
  storage,
});

overrideStorage(backend, { envName: branchName, projectName: '<hard-code-project-name>' });

Describe alternatives you've considered

None

Additional context

Note that resources.s3Bucket is far from the only resource available for override. The full list is available here:

export interface AmplifyS3ResourceTemplate extends AmplifyCDKL1 {
s3Bucket?: s3Cdk.CfnBucket;
s3AuthPublicPolicy?: iamCdk.CfnPolicy;
s3AuthProtectedPolicy?: iamCdk.CfnPolicy;
s3AuthPrivatePolicy?: iamCdk.CfnPolicy;
s3AuthUploadPolicy?: iamCdk.CfnPolicy;
s3AuthReadPolicy?: iamCdk.CfnPolicy;
s3GuestPublicPolicy?: iamCdk.CfnPolicy;
s3GuestUploadPolicy?: iamCdk.CfnPolicy;
s3GuestReadPolicy?: iamCdk.CfnPolicy;
}

export interface AmplifyDDBResourceTemplate extends AmplifyCDKL1 {
dynamoDBTable?: ddb.CfnTable;
}

Each one of them would likely require its own special transformation. Some transformations may not even be possible. For example, resources.s3AuthPublicPolicy does not directly map to any Gen2 resource since Gen2 manages storage policies differently.

Is this something that you'd be interested in working on?

  • 👋 I may be able to implement this feature request

Would this feature include a breaking change?

  • ⚠️ This feature might incur a breaking change

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions