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

aws-ecs (all): validation should leverage typescript type system #29343

Open
2 tasks
cheruvian opened this issue Mar 1, 2024 · 3 comments
Open
2 tasks

aws-ecs (all): validation should leverage typescript type system #29343

cheruvian opened this issue Mar 1, 2024 · 3 comments
Labels
@aws-cdk/aws-ecs Related to Amazon Elastic Container effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2

Comments

@cheruvian
Copy link
Contributor

Describe the feature

Audit either/or validations across the CDK and add appropriate types to the interfaces for build time validation rather than runtime validation.

Use Case

I've seen this in a couple places but most recently with

this.taskDefinition.addFirelensLogRouter('FluentBitLogRouter', {
      image: ContainerImage.fromRegistry('amazon/aws-for-fluent-bit:latest'),
      firelensConfig: {
        type: FirelensLogRouterType.FLUENTBIT,
        options: {
          enableECSLogMetadata: true,
        },
      },
}

Which results in the following error

ECS Container FluentBitLogRouter must have at least one of 'memoryLimitMiB' or 'memoryReservationMiB' specified

Proposed Solution

Current:

addFirelensLogRouter(id: string, props: FirelensLogRouterDefinitionOptions): FirelensLogRouter;

Proposed:

addFirelensLogRouter(id: string, props: FirelensLogRouterDefinitionOptions & ({ memoryLimitMiB: number } | { memoryReservationMiB: number })): FirelensLogRouter;

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

all

Environment details (OS name and version, etc.)

OSX

@cheruvian cheruvian added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Mar 1, 2024
@github-actions github-actions bot added the @aws-cdk/aws-ecs Related to Amazon Elastic Container label Mar 1, 2024
@luxaritas
Copy link
Contributor

From my understanding, these kinds of API definitions are explicitly avoided since many target languages of the CDK can't represent them: https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md#unions

@pahud
Copy link
Contributor

pahud commented Mar 2, 2024

That's right. Thank you.

@pahud pahud added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. p2 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Mar 2, 2024
@cheruvian
Copy link
Contributor Author

While I understand the need, as a majority of documentation and, from my understanding, usage is TypeScript we should consider improving the native TypeScript usage.

The approach would seem to be to fairly straightforward to resolve and merge the type in as optional for languages that do not support unions.

e.g.

interface Reqs { a: number }
interface Opt1 { b: number }
interface Opt2 { c: number }
type API = Reqs & (Opt1 | Opt2)

// becomes

type API_M = Reqs & Optional<Opt1> & Optional<Opt2>

I'm certain an actual jsii implementation would require some thought but it seems achievable at first glance.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Mar 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ecs Related to Amazon Elastic Container effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

No branches or pull requests

3 participants