Skip to content

Allow Inline Lambda Function Definitions #287

Closed

Description

@talawahtech

It would be be great if we could define the code for Lambda functions inline. This functionality already exists for AWS::Lambda::Function resources and it is very convenient for things like Custom Resources that execute as part of the CloudFormation template or really simple Lambda@Edge functions.

Of course it would be understood if there needs to be a limit to the number of characters.

E.g. of current usage in a regular CloudFormation template

Resources:
  StaticSiteHelper: 
    Type: "AWS::Lambda::Function"
    Description: "Implements index.html support for directories &redirects to add a trailing slash"
    Properties: 
      Handler: "index.handler"
      Role: !GetAtt LambdaRole.Arn
      Code:
        ZipFile: |
          exports.handler = (event, context, callback) => {
            const request = event.Records[0].cf.request;
            const matchArray = request.uri.match(/[^/]+$/);
              
            if (matchArray === null){
              request.uri = request.uri.replace(/\/$/, '\/index.html');        
              return callback(null, request);
            }	
            else if (matchArray[0].includes('.') === false){
              const response = {
                status: '302',
                headers: { location: [{ key: 'Location',value: request.uri + '/' }] }
              };
              return callback(null, response);
            }

            return callback(null, request);
          };
      Runtime: "nodejs6.10"
      Timeout: "30"

Activity

  1. brettstack commented on Jun 27, 2018

    @brettstack
    Contributor

    Added in #447

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions