(aws-s3-deployment): Bucket Deployment Lambda generation doesn't follow ARN length standards
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 71
Description
### Describe the bug
** Couldn't find on the module documentation any way to assign/override the name for the lambda function (search on google also didn't throw any particular solution)
From CDK I was able to make use of the [BucketDeployment](https://docs.aws.amazon.com/cdk/api/v1/docs/@aws-cdk_aws-s3-deployment.BucketDeployment.html) while compiling my project locally; But during the actual deployment on CloudFormation I received an error due to a Lambda layer that gets generated through the BucketDeployment construct which broke the ARN max length.
### Expected Behavior
CDK Lib to be either notify of this prior to deploying to CloudFormation, or for the module to be smart enough to appropriately shorten the name length to fit within the ARN standards
### Current Behavior
Build succeeds locally, but while the deployment of the CDK template occurs on CloudFormation, it fails with the following error
```
Resource handler returned message: "1 validation error detected: Value '[arn:aws:lambda:us-west-2:123456789012:layer:SomeNameConcatenationThatIsLongerThan80CharactersLongAwsCliLayer3DA59007:1]' at 'layers' failed to satisfy constraint: Member must satisfy constraint: [Member must have length less than or equal to 140, Member must have length greater than or equal to 1, Member must satisfy regular expression pattern: (arn:[a-zA-Z0-9-]+:lambda:[a-zA-Z0-9-]+:\d{12}:layer:[a-zA-Z0-9-_]+:[0-9]+)|(arn:[a-zA-Z0-9-]+:lambda:::awslayer:[a-zA-Z0-9-_]+), Member must not be null] (Service: Lambda, Status Code: 400, Request ID: 7fbbe2e6-b5cf-4d93-a437-449c5ee2f4f9)" (RequestToken: d8304a82-526c-11f1-ab7f-7cf639c790d5, HandlerErrorCode: InvalidRequest)
```
The above layer is created as part of the Bucket Deployment utility provided by the CDK module
### Reproduction Steps
Create a stack which includes a construct with an id with the following setup
`this.customUploader = new Uploader(this, `IdIsANameWithALengthOfAtLeast58Characters`, {...})`
Length should be defined only by [A-Z][a-z] characters as special characters i.e. `-` are removed from the concatenation.
Inside the construct include the BucketDeployment with a setup similar to
`const bucketDeployment = new BucketDeployment(this, 'IdIsANameWithALengthOfAtLeast24Characters', {...})`
The above will generate during the CloudFormation deployment a Lambda function with the following concatenation
`arn:aws:lambda:region:123456789012:layer:IdIsANameWithALengthOfAtLeast58CharactersIdIsANameWithALengthOfAtLeast24CharactersAwsCliLayerRandomIDDisambiguator`
Which then fails the generation of the stack due to the error mentioned above
### Possible Solution
Couple of possible choices:
* Allow customers to provide the names of the lambdas to be generated over the construct definition as optionals
* Review the concatenation length of the `Id` to trim/truncate on it as to avoid surpassing the Lambda standard for ARN generation
### Additional Information/Context
_No response_
### CDK CLI Version
2.46.0
### Framework Version
_No response_
### Node.js Version
14
### OS
MacOS Ventura 13.3.1
### Language
Typescript
### Language Version
4.8.4
### Other information
_No response_
Contributor guide
Research direction
Start at the BucketDeployment construct and its generated Lambda and layer naming during CloudFormation synthesis; inspect how construct IDs become the ARN components. Reproduce the long-ID case and verify that deployment either keeps the generated ARN within AWS Lambda's stated limits or reports the problem before CloudFormation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- cloud, infrastructure
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100