Skip to content

Fn::Split support? #38

Closed
serverless/serverless
#9266

Description

@omar-dulaimi

Hello,

I'm getting this validation error locally in my serverless.ts file:

Type '{ 'Fn::Split': string[]; }' is not assignable to type 'AwsCfInstruction[]'.
  Object literal may only specify known properties, and ''Fn::Split'' does not exist in type 'AwsCfInstruction[]'.ts(2322)
index.d.ts(1331, 3): The expected type comes from property 'securityGroupIds' which is declared here on type 'AwsLambdaVpcConfig'

So I looked into the library code and couldn't find it mentioned anywhere. I saw the others though, like Fn::Join and the rest.

This brings my question, is the split method supported? Because I checked the later releases after v2.29.0 commit by commit and nothing was there(A change log would be really great by the way).

Activity

  1. changed the title [-]Fn::Join support?[/-] [+]Fn::Split support?[/+] on Apr 7, 2021
  2. omar-dulaimi commented on Apr 7, 2021

    @omar-dulaimi
    Author

    Okay, So I ended up doing this:

            vpc: ({
                securityGroupIds: {
                    'Fn::Split': [',', '${env:SECURITY_GROUP_IDS}'],
                },
                subnetIds: {
                    'Fn::Split': [',', '${env:SUBNET_IDS}'],
                },
            } as unknown) as AwsLambdaVpcConfig,
    

    But I get this warning while deploying:

    Serverless: Configuration warning:
    Serverless:   at 'provider.vpc.securityGroupIds': should be array
    Serverless:   at 'provider.vpc.subnetIds': should be array
    
  3. fredericbarthelet commented on Apr 8, 2021

    @fredericbarthelet
    Contributor

    Hi @omar-dulaimi and thanks for reporting your issue.
    This repository aims to contains only TypeScript definitions compiled from Serverless core framework internal validation logic.
    If you ignore the TS error showing that using Fn::Split is not a valid property for securityGroupIds, you'd still have the framework complaining about it (hence the warning you got on your second try).

    I opened a PR aiming at allowing such use of Fn::Split, but I'm not sure wether additional development should be done in https://github.com/serverless/serverless/blob/dac06c8ce644f0d219329474cb83c644ca61d880/lib/plugins/aws/deployFunction.js#L283-L289 and https://github.com/serverless/serverless/blob/dac06c8ce644f0d219329474cb83c644ca61d880/lib/plugins/aws/package/compile/functions.js#L364-L376

  4. pveller commented on Apr 9, 2021

    @pveller

    Not a directly related question but I would appreciate your guidance. Now that type definitions are auto-generated, certain things are much clearer and certain things are not. Please take a look at stream event definition:

    I do this:

          events: [
            {
              stream: {
                arn: {
                  'Fn::GetAtt': ['MyTable', 'StreamArm'],
                },
                batchSize: 1,
              },
            },
          ],
    

    and serverless fails fast on functions.propagate.events[0].stream.arn': should be string with configValidationMode: 'error'. If I turn off configValidationMode, serverless package fails on EventSourceArn.split is not a function. This has been talked about long time ago here serverless/serverless#2365 and later fixed here serverless/serverless#3111.

    The fix was simple - adding an explicit type attribute to the stream event definition. DefinitelyTyped has it (https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/serverless/plugins/aws/provider/awsProvider.d.ts#L408):

        interface Stream {
            arn: string | { [key: string]: any };
            batchSize?: number | string;
            startingPosition?: number | string;
            enabled?: boolean;
            type?: 'dynamodb' | 'kinesis';
        }
    

    but it's lost in auto-generated types:

            {
                stream:
                  | AwsArnString
                  | (
                      | {
                          arn: AwsCfFunction;
                          [k: string]: unknown;
                        }
                      | {
                          arn: AwsArnString;
                          [k: string]: unknown;
                        }
                    );
              }
    

    So my question is - where to submit a PR or an Issue to get back those typed attributes into the generated type definitions? Adding type solved my problem but it would be nice if it was visible on the type def and thus accessible via auto-complete

    Thanks!

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

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions