aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.65k stars 3.91k forks source link

(construct): consistent naming for construct resources #15206

Open gliptak opened 3 years ago

gliptak commented 3 years ago

cdk generates below naming pattern like stackName-constructNameresourceNamepostfix

note no dash between constructName and resourceName

https://cdkworkshop.com/30-python/40-hit-counter/logs1.png image

Use Case

Separating constructName and resourceName with dash makes listing of resources more readable and consistent with stackName approach

Proposed Solution

Separate with dash constructName and resourceName

Other


This is a :rocket: Feature Request

ryparker commented 3 years ago

Hey @gliptak :wave:

Thanks for suggesting this feature request. If you're in need of a workaround you can always name the lambda function manually via the functionName prop. See CDK lambda docs

I am marking this issue as p2 which means that we are unable to work on this immediately. We use +1s to help us prioritize our work, and as always we are happy to take contributions if anyone is interested to pick this up and submit a PR (please make sure to follow our contribution guidelines.)

gliptak commented 3 years ago

@ryparker any pointers on what changes might this require (and I will work towards a PR)?

ryparker commented 3 years ago

After investigating this a little to try and find a good starting place, I found that I was not able to reproduce the naming that you're seeing. Could you provide some repro code?

Here's what I see:

Code:

import * as cdk from '@aws-cdk/core';
import * as lambda from '@aws-cdk/aws-lambda';

class LambdaStack extends cdk.Stack {
  constructor(scope: cdk.App, name: string, props?: cdk.StackProps) {
    super(scope, name, props);

    new lambda.Function(this, 'lambdaFunction1', {
      code: lambda.Code.fromInline('// code'),
      handler: 'index.handler',
      runtime: lambda.Runtime.NODEJS_10_X,
    });
  }
};

const app = new cdk.App();
new LambdaStack(app, 'LambdaStack')

Output:

CleanShot 2021-06-29 at 09 58 00@2x

gliptak commented 3 years ago

@ryparker thank you for looking into this. The code came from below repo, subclassing core.Construct (not cdk.Stack)

https://github.com/aws-samples/aws-cdk-intro-workshop/blob/master/code/python/main-workshop/cdk-workshop/hitcounter.py#L7

class HitCounter(core.Construct):
github-actions[bot] commented 2 years ago

This issue has not received any attention in 1 year. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

gliptak commented 2 years ago

code location https://github.com/aws-samples/aws-cdk-intro-workshop/blob/master/code/python/main-workshop/cdk_workshop/hitcounter.py