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

(Amazon.CDK.AWS.CloudFront.Experimental): Stack fails to publish when edge function is included #16832

Closed
Mike-Gilge opened this issue Oct 6, 2021 · 2 comments · Fixed by #16845
Labels
@aws-cdk/aws-cloudfront Related to Amazon CloudFront bug This issue is a bug. effort/small Small work item – less than a day of effort in-progress This issue is being actively worked on. p2

Comments

@Mike-Gilge
Copy link

Mike-Gilge commented Oct 6, 2021

What is the problem?

When I try to publish my stack with an EdgeFunction it is failing on the outputted ssm parameter. Nothing I have tried makes any difference.

Reproduction Steps

           CloudFrontDistribution = new Distribution(this, "Work Remote Cloudfront distribution", new DistributionProps
           {
               DefaultBehavior = new BehaviorOptions
               {
                   Origin = new S3Origin(WebsiteBucket),
                   ViewerProtocolPolicy = ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
                   EdgeLambdas = new IEdgeLambda[]{new EdgeLambda
                   {
                       EventType = LambdaEdgeEventType.ORIGIN_REQUEST,
                       IncludeBody = true,
                       FunctionVersion = new EdgeFunction(this, "AWS MarketplaceRedirect", new EdgeFunctionProps
                       {
                           FunctionName = "AwsMarketplaceRedirect",
                           Runtime = Runtime.NODEJS_12_X,
                           Code = Code.FromAsset("src/VegaWorkRemoteBackendStack"),
                           Handler = "AwsMarketplaceRedirect.lambdaHandler",
                       }).CurrentVersion
                   }}
               },
               //This allows spa to function correctly
               ErrorResponses = new IErrorResponse[]{new ErrorResponse
               {
                   HttpStatus = 404,
                   Ttl = Duration.Seconds(0),
                   ResponsePagePath = "/index.html",
                   ResponseHttpStatus = 200
               }},
           });

What did you expect to happen?

I would expect the stack to publish and for a lambda edge to be set up with CloudFront.

What actually happened?

4/6 | 3:37:08 PM | CREATE_IN_PROGRESS   | AWS::SSM::Parameter   | AWS MarketplaceRedirect/Parameter (AWSMarketplaceRedirectParameter9203C56D) 
 4/6 | 3:37:09 PM | CREATE_FAILED        | AWS::SSM::Parameter   | AWS MarketplaceRedirect/Parameter (AWSMarketplaceRedirectParameter9203C56D) Parameter name: can't be prefixed with "ssm" (case-insensitive). If formed as a path, it can consist of sub-paths divided by slash symbol; each sub-path can be formed as a mix of letters, numbers and the following 3 symbols .-_ (Service: AmazonSSM; Status Code: 400; Error Code: ValidationException; Request ID: 211ea5fc-b166-4569-b713-41ac6b123518; Proxy: null)
   new StringParameter (/private/var/folders/3v/9ls13tw104s2vyzzyzbsggh80000gn/T/jsii-kernel-3vSJaz/node_modules/@aws-cdk/aws-ssm/lib/parameter.js:98:26)
   \_ EdgeFunction.createCrossRegionFunction (/private/var/folders/3v/9ls13tw104s2vyzzyzbsggh80000gn/T/jsii-kernel-3vSJaz/node_modules/@aws-cdk/aws-cloudfront/lib/experimental/edge-function.js:229:9)
   \_ new EdgeFunction (/private/var/folders/3v/9ls13tw104s2vyzzyzbsggh80000gn/T/jsii-kernel-3vSJaz/node_modules/@aws-cdk/aws-cloudfront/lib/experimental/edge-function.js:41:20)
   \_ /private/var/folders/3v/9ls13tw104s2vyzzyzbsggh80000gn/T/trhycroh.fhm/lib/program.js:8432:58
   \_ Kernel._wrapSandboxCode (/private/var/folders/3v/9ls13tw104s2vyzzyzbsggh80000gn/T/trhycroh.fhm/lib/program.js:8860:24)
   \_ Kernel._create (/private/var/folders/3v/9ls13tw104s2vyzzyzbsggh80000gn/T/trhycroh.fhm/lib/program.js:8432:34)
   \_ Kernel.create (/private/var/folders/3v/9ls13tw104s2vyzzyzbsggh80000gn/T/trhycroh.fhm/lib/program.js:8173:29)
   \_ KernelHost.processRequest (/private/var/folders/3v/9ls13tw104s2vyzzyzbsggh80000gn/T/trhycroh.fhm/lib/program.js:9757:36)
   \_ KernelHost.run (/private/var/folders/3v/9ls13tw104s2vyzzyzbsggh80000gn/T/trhycroh.fhm/lib/program.js:9720:22)
   \_ Immediate._onImmediate (/private/var/folders/3v/9ls13tw104s2vyzzyzbsggh80000gn/T/trhycroh.fhm/lib/program.js:9721:46)
   \_ processImmediate (internal/timers.js:464:21)
 4/6 | 3:37:10 PM | ROLLBACK_IN_PROGRESS | AWS::CloudFormation::Stack | edge-lambda-stack-c8a3e34b082c95e9bff7304ce956ae2ceb3b1462d1 The following resource(s) failed to create: [AWSMarketplaceRedirectParameter9203C56D]. Rollback requested by user.

CDK CLI Version

1.126.0

Framework Version

No response

Node.js Version

v14.17.1

OS

Mac OS 11.6

Language

.NET

Language Version

No response

Other information

No response

@Mike-Gilge Mike-Gilge added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 6, 2021
@github-actions github-actions bot added the @aws-cdk/aws-cloudfront Related to Amazon CloudFront label Oct 6, 2021
@njlynch
Copy link
Contributor

njlynch commented Oct 7, 2021

The error message you're getting kind of spells out the issue, but certainly not as clearly as it could:

Parameter name: can't be prefixed with "ssm" (case-insensitive). If formed as a path, it can consist of sub-paths divided by slash symbol; each sub-path can be formed as a mix of letters, numbers and the following 3 symbols .-_

The SSM parameter name is being built off of a well-defined prefix, plus the construct path to the EdgeFunction (e.g. 'StackName/Work Remote Cloudfront distribution/AWS MarketplaceRedirect'). That name can only contain letters, numbers, and the above symbols, but not spaces.

The quick work-around is to remove the spaces from your construct IDs (e.g., AWSMarketplaceRedirect). The fix here would be to (a) add validation to SSM so this can be caught at build/synth time, rather than deploy time; (b) strip spaces (and other disallowed characters) from the path before passing to SSM.

njlynch added a commit that referenced this issue Oct 7, 2021
The EdgeFunction uses a SSM string parameter under the hood to pass the Function
ARN between the different regions. The name of the parameter is derived from the
node path; this path may contain characters (e.g., spaces) that are invalid as
SSM parameter names.

Two fixes here: introduce new validation for SSM parameter names, and sanitize
the path prior to passing to SSM.

fixes #16832
@njlynch njlynch added effort/small Small work item – less than a day of effort in-progress This issue is being actively worked on. p2 and removed needs-triage This issue or PR still needs to be triaged. labels Oct 7, 2021
@njlynch njlynch removed their assignment Oct 7, 2021
@mergify mergify bot closed this as completed in #16845 Oct 7, 2021
mergify bot pushed a commit that referenced this issue Oct 7, 2021
…ces (#16845)

The EdgeFunction uses a SSM string parameter under the hood to pass the Function
ARN between the different regions. The name of the parameter is derived from the
node path; this path may contain characters (e.g., spaces) that are invalid as
SSM parameter names.

Two fixes here: introduce new validation for SSM parameter names, and sanitize
the path prior to passing to SSM.

fixes #16832


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

github-actions bot commented Oct 7, 2021

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

njlynch added a commit that referenced this issue Oct 11, 2021
…ces (#16845)

The EdgeFunction uses a SSM string parameter under the hood to pass the Function
ARN between the different regions. The name of the parameter is derived from the
node path; this path may contain characters (e.g., spaces) that are invalid as
SSM parameter names.

Two fixes here: introduce new validation for SSM parameter names, and sanitize
the path prior to passing to SSM.

fixes #16832


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this issue Feb 21, 2022
…ces (aws#16845)

The EdgeFunction uses a SSM string parameter under the hood to pass the Function
ARN between the different regions. The name of the parameter is derived from the
node path; this path may contain characters (e.g., spaces) that are invalid as
SSM parameter names.

Two fixes here: introduce new validation for SSM parameter names, and sanitize
the path prior to passing to SSM.

fixes aws#16832


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-cloudfront Related to Amazon CloudFront bug This issue is a bug. effort/small Small work item – less than a day of effort in-progress This issue is being actively worked on. p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants