aws-amplify / aws-amplify/amplify-cli

(gen2-migration) `generate` command should handle storage overrides

Open
#14,640 0 comments 0 reactions 0 assignees View on GitHub
gen2-migration
Dominant language
TypeScript
Stars
2.9k
Forks
825
Avg merge
11d 23h
Merged PRs (30d)
2

Description

### 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

```ts
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:

```ts
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:

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

And then invoke this function from `backend.ts`:

```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: '' });
```

### 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:

https://github.com/aws-amplify/amplify-cli/blob/664dabc422d81153a3193996a7324d27829ef3b9/packages/amplify-cli-extensibility-helper/src/types/storage/types.ts#L27-L37

https://github.com/aws-amplify/amplify-cli/blob/664dabc422d81153a3193996a7324d27829ef3b9/packages/amplify-cli-extensibility-helper/src/types/storage/types.ts#L20-L22

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.