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

Bug: Serverless Api: Incorrect handling of !If statement #7433

Closed
bel-gacem opened this issue Sep 2, 2024 · 3 comments
Closed

Bug: Serverless Api: Incorrect handling of !If statement #7433

bel-gacem opened this issue Sep 2, 2024 · 3 comments
Labels
area/intrinsics Ref, If, Sub, GetAtt, ... type/question

Comments

@bel-gacem
Copy link

Description:

Hi, looks like the Domain property of the serverless api resource does not support !If statement.

Steps to reproduce:

Conditions:
  EnableCustomDomain: !Not [!Equals [!Ref SubDomainName, '']]
Resources:
  RestApi:
    Type: AWS::Serverless::Api
    Properties:
      Name: !Sub restapi-${Deployment}
      StageName: v1
      OpenApiVersion: 3.0.3
      DefinitionBody: !Transform
        Name: AWS::Include
        Parameters:
          Location: spec/openapi.yaml
      EndpointConfiguration:
        Type: REGIONAL
      Domain: !If
        - EnableCustomDomain
        - DisableExecuteApiEndpoint: true
          BasePath:
            - /v1
          CertificateArn: !Ref SSLCertificateArn
          DomainName: !Sub ${DnsHostId}.${SubDomainName}
          EndpointConfiguration: REGIONAL
          SecurityPolicy: TLS_1_2
          Route53:
            HostedZoneName: !Sub ${SubDomainName}.
        - !Ref AWS::NoValue

Observed result:

$ sam validate
[[E0001: Error found when transforming the template] (Error transforming template: Resource with id [RestApi] is invalid. Property 'Domain.DomainName' is required.) matched 1]
Error: Linting failed. At least one linting rule was matched to the provided template.

$ sam deploy
Waiting for changeset to be created..
Error: Failed to create changeset for the stack: app-dev, ex: Waiter ChangeSetCreateComplete failed: Waiter encountered a terminal failure state: For expression "Status" we matched expected path: "FAILED" Status: FAILED. Reason: Transform AWS::Serverless-2016-10-31 failed with: Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [RestApi] is invalid. Property 'Domain.DomainName' is required.

Expected result:

Both the validation and the deployment are successful.

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: Ubuntu 22.04.3 LTS
  2. sam --version: 1.123.0
  3. AWS region: us-east-1
{
  "version": "1.123.0",
  "system": {
    "python": "3.11.8",
    "os": "Linux-5.15.153.1-microsoft-standard-WSL2-x86_64-with-glibc2.35"
  },
  "additional_dependencies": {
    "docker_engine": "24.0.5",
    "aws_cdk": "Not available",
    "terraform": "1.7.3"
  },
  "available_beta_feature_env_vars": [
    "SAM_CLI_BETA_FEATURES",
    "SAM_CLI_BETA_BUILD_PERFORMANCE",
    "SAM_CLI_BETA_TERRAFORM_SUPPORT",
    "SAM_CLI_BETA_RUST_CARGO_LAMBDA"
  ]
}
@bel-gacem bel-gacem added the stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. label Sep 2, 2024
@hnnasit
Copy link
Contributor

hnnasit commented Sep 10, 2024

Hi @bel-gacem, SAM and SAM CLI has some basic intrinsics support, but unfortunately it doesn't cover all cases. Have a look at the SAM issue to check the unsupported intrinsics.

@hnnasit hnnasit added type/question area/intrinsics Ref, If, Sub, GetAtt, ... and removed stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels Sep 10, 2024
@bel-gacem
Copy link
Author

Thanks @hnnasit, closing the issue.

Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/intrinsics Ref, If, Sub, GetAtt, ... type/question
Projects
None yet
Development

No branches or pull requests

2 participants