aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

@aws-cdk/aws-sam.CfnFunction: Add support for inline code instead of codeUri

Open lintal opened this issue 5 years ago • 4 comments

Currently it is only possible to deploy a CfnFunction where a codeUri parameter is included. In raw CloudFormation however, you can deploy an aws::serverless::function with an inlineCode property without codeUri.

Use Case

Our organisation's deployment pipeline requires the AWS resources (the Lambda function) to exist first before we deploy code to them. Therefore we need to be able to deploy a Lambda with a very minimal inline-code snippet.

After creation, our deployment pipeline can then install the code from our repository.

Proposed Solution

Add support to CfnFunction so that either a codeUri or inlineCode property must be provided.

Other

Example stack:

import * as cdk from '@aws-cdk/core';
import { Runtime } from '@aws-cdk/aws-lambda'
import { CfnFunction } from '@aws-cdk/aws-sam';

export class MyStack extends cdk.Stack {
  constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);
    
    // No option to NOT provide `codeUri` & no option to include `inlineCode`
    new CfnFunction(this, 'LambdaFunction', {
      codeUri: '.',
      handler: 'index.handler',
      runtime: Runtime.NODEJS_12_X.toString(),
    });
  }
}

When attempting to deploy:

npx cdk deploy

my-project-stack: deploying...
my-project-stack: creating CloudFormation changeset...

 ❌  my-project-stack failed: Error: Failed to create ChangeSet cdk-deploy-change-set on my-project-stack: FAILED, Transform AWS::Serverless-2016-10-31 failed with: Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [LambdaFunction] is invalid. 'CodeUri' is not a valid S3 Uri of the form 's3://bucket/key' with optional versionId query parameter.
    at /path/to/my/project/node_modules/aws-cdk/lib/api/util/cloudformation.ts:227:11
    at processTicksAndRejections (node:internal/process/task_queues:94:5)
    at waitFor (/path/to/my/project/node_modules/aws-cdk/lib/api/util/cloudformation.ts:188:20)
    at Object.waitForChangeSet (/path/to/my/project/node_modules/aws-cdk/lib/api/util/cloudformation.ts:213:15)
    at Object.deployStack (/path/to/my/project/node_modules/aws-cdk/lib/api/deploy-stack.ts:263:32)
    at CdkToolkit.deploy (/path/to/my/project/node_modules/aws-cdk/lib/cdk-toolkit.ts:180:24)
    at initCommandLine (/path/to/my/project/node_modules/aws-cdk/bin/cdk.ts:208:9)
Failed to create ChangeSet cdk-deploy-change-set on my-project-stack: FAILED, Transform AWS::Serverless-2016-10-31 failed with: Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [LambdaFunction] is invalid. 'CodeUri' is not a valid S3 Uri of the form 's3://bucket/key' with optional versionId query parameter.
npm ERR! code 1
npm ERR! path /path/to/my/project
npm ERR! command failed
npm ERR! command sh -c cdk "deploy"

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/my-user/.npm/_logs/2021-03-26T16_04_22_439Z-debug.log

Any attempts to point codeUri at a fictitious bucket / object-key also results in failure.

  • [ ] :wave: I may be able to implement this feature request
  • [ ] :warning: This feature might incur a breaking change

This is a :rocket: Feature Request

lintal avatar Mar 26 '21 16:03 lintal

Hey @lintal ,

thanks for opening the issue. We are aware of the problem: https://github.com/aws/aws-cdk/issues/13507.

Can you +1 that issue?

Thanks, Adam

skinny85 avatar Mar 26 '21 16:03 skinny85

Thanks @skinny85 - I have done that now.

lintal avatar Mar 26 '21 16:03 lintal

Closing this one in favor of #13507.

njlynch avatar Mar 29 '21 13:03 njlynch

⚠️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.

github-actions[bot] avatar Mar 29 '21 13:03 github-actions[bot]