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

Support CloudFormation intrinsic functions #49

Closed
Chriscbr opened this issue Apr 12, 2022 · 1 comment
Closed

Support CloudFormation intrinsic functions #49

Chriscbr opened this issue Apr 12, 2022 · 1 comment
Assignees
Labels
feature-request A feature should be added or improved. p1

Comments

@Chriscbr
Copy link
Contributor

Chriscbr commented Apr 12, 2022

Currently, trying to use an intrinsic function in most places where a specific value is expected (such as a string) results in an error:

AppSyncEventBridgeRole:
  Type: aws-cdk-lib.aws_iam.Role
  Properties:
    assumedBy:
      aws-cdk-lib.aws_iam.ServicePrincipal:
        service:
          Fn::Sub:
            - 'appsync.${Domain}.com'
            - Domain:
                Ref: amazonaws

which produces the following error:

TypeError: (displayHint || "TOKEN").replace is not a function

Instead, it should generate the equivalent function in the core API (https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.Fn.html).

This should support using both the "long form" (e.g. Fn::Sub) and "short form" (e.g. !Sub -- only available in YAML) of each intrinsic function. These are documented on the pages about intrinsic functions: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-join.html


Note: in some rare cases it does work, but I think it's just because CDK doesn't check the values passed to environment:

connectFunction:
  Type: aws-cdk-lib.aws_lambda.Function
  Properties:
    handler: index.handler
    runtime: NODEJS_14_X
    timeout:
      seconds:
        amount: 300
    code:
      fromInline:
        code: exports.handler = function() { console.log("hello world"); }
    memorySize: 256
    environment:
      ENV_VAR:
        Fn::Join:
          - "arn:aws:lambda"
          - ":"
          - "us-east-1"
          - ":"
          - "111122223333"
          - ":function:"
          - "my-function"

For the implementation, consider checking out these related PRs in the AWS CDK:


Split out to #270

Also, trying to reference one of the "short forms" in a template immediately causes an error during parsing:

(node:71590) YAMLWarning: The tag !Sub is unavailable, falling back to tag:yaml.org,2002:seq
@Chriscbr Chriscbr added bug Something isn't working feature-request A feature should be added or improved. and removed bug Something isn't working labels Apr 12, 2022
@mrgrain mrgrain added this to the Milestone 1 - E2E milestone Aug 31, 2022
@mrgrain mrgrain self-assigned this Sep 13, 2022
mergify bot pushed a commit that referenced this issue Sep 15, 2022
…pected (#263)

First part of #49

--- 

- Adds proper JsonSchema for Intrinsics
- Test suite for AST support (which was already there)
- One fix for AST and evaluation of Join/Select intrinsics

---

Coming in a follow-up:
- Test suite for evaluation
- Context for intrinsics
@mrgrain
Copy link
Contributor

mrgrain commented Sep 15, 2022

Closing in favor of #275

@mrgrain mrgrain closed this as completed Sep 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A feature should be added or improved. p1
Projects
None yet
Development

No branches or pull requests

3 participants