aws-extensions-for-dotnet-cli icon indicating copy to clipboard operation
aws-extensions-for-dotnet-cli copied to clipboard

Extend template-parameter definition syntax in serverless configuration file

Open jasonterando opened this issue 1 year ago • 1 comments

Describe the feature

Extend supported syntax for defining "template-parameters" in serverless template configuration JSON files to include object and array syntax.

Use Case

If deploying a serverless template with a lot of parameters, the format "key1=value1;key2=value2;...keyN=valueN" becomes difficult to manage, especially if you are creating multiple configuration to support different environments (ex. Q/A, staging, production).

Proposed Solution

Update AmazonLambdaTools to check the parameter type for template-parameters.

  • [Current] If it's a string, generate a Dictionary using current syntax ("key1=value1;key2=value2;...keyN=valueN")
  • [New] If it's an object, process it using property names for keys and cast values as string
  • [New] If it's an array of strings, process it using the syntax supported by SAM, which s a list of "key=value" strings

This approach is backward compatible, it won't break usage of existing template files.

Current Format (string)

{
    "template-parameters": "Secret1ARN=arn:aws:secretsmanager:us-west-1:999888777666:secret:db.mysecret3-AbCdEf;Secret2ARN=arn:aws:secretsmanager:us-west-1:999888777666:secret:mysecret2-GhIkJl;DNSName=leads-aot;AspNetCoreEnvironment=qa;Stage=live;DNSDomain=my-domain.net;HostedZoneId=Z001329499ABC;CertificateArn=arn:aws:acm:us-west-1:999888777666:certificate/111111-aa-2222-cccc-9999999999999;UserPoolId=us-west-1_YzYzYzYzYz;CognitoUserPoolArn=arn:aws:cognito-idp:us-west-1:999888777666:userpool/us-west-1_YzYzYzYzYz;VpcEndpointId=vpce-02e2c2b9db2c3b9f6;LoadBalancerDns=private-my-domain-net-lb-c12345d987654.elb.us-west-1.amazonaws.com;VpcSubnetIds=subnet-111111,subnet-222222;VpcSecurityGroupIds=sg-00011122233334444"
}

New Format (object)

    "template-parameters": {
        "Secret1ARN": "arn:aws:secretsmanager:us-west-1:999888777666:secret:db.mysecret3-AbCdEf",
        "Secret2ARN": "arn:aws:secretsmanager:us-west-1:999888777666:secret:mysecret2-GhIkJl",
        "DNSName": "leads-aot",
        "AspNetCoreEnvironment": "qa",
        "Stage": "live",
        "DNSDomain": "my-domain.net",
        "HostedZoneId": "Z001329499ABC",
        "CertificateArn": "arn:aws:acm:us-west-1:999888777666:certificate/111111-aa-2222-cccc-9999999999999",
        "UserPoolId": "us-west-1_YzYzYzYzYz",
        "CognitoUserPoolArn": "arn:aws:cognito-idp:us-west-1:999888777666:userpool/us-west-1_YzYzYzYzYz",
        "VpcEndpointId": "vpce-02e2c2b9db2c3b9f6",
        "LoadBalancerDns": "private-my-domain-net-lb-c12345d987654.elb.us-west-1.amazonaws.com",
        "VpcSubnetIds": "subnet-111111,subnet-222222",
        "VpcSecurityGroupIds": "sg-00011122233334444"
    },

New Format (array - SAM compatible)

{
    "template-parameters": [
        "Secret1ARN=arn:aws:secretsmanager:us-west-1:999888777666:secret:db.mysecret3-AbCdEf",
        "Secret2ARN=arn:aws:secretsmanager:us-west-1:999888777666:secret:mysecret2-GhIkJl",
        "DNSName=leads-aot",
        "AspNetCoreEnvironment=qa",
        "Stage=live",
        "DNSDomain=my-domain.net",
        "HostedZoneId=Z001329499ABC",
        "CertificateArn=arn:aws:acm:us-west-1:999888777666:certificate/111111-aa-2222-cccc-9999999999999",
        "UserPoolId=us-west-1_YzYzYzYzYz",
        "CognitoUserPoolArn=arn:aws:cognito-idp:us-west-1:999888777666:userpool/us-west-1_YzYzYzYzYz",
        "VpcEndpointId=vpce-02e2c2b9db2c3b9f6",
        "LoadBalancerDns=private-my-domain-net-lb-c12345d987654.elb.us-west-1.amazonaws.com",
        "VpcSubnetIds=subnet-111111,subnet-222222",
        "VpcSecurityGroupIds=sg-00011122233334444"
    ]
}

Other Information

I'll be submitting a PR implementing this change

Acknowledgements

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

Targeted .NET platform

(All)

CLI extension version

No response

Environment details (OS name and version, etc.)

Any

jasonterando avatar Dec 18 '22 16:12 jasonterando

Needs review with the team. Customer has proposed a PR.

ashishdhingra avatar Dec 27 '22 19:12 ashishdhingra