Skip to content

Conditional FunctionUrlConfig deploy error - in AWS::Serverless::Function #2385

@semmi88

Description

@semmi88

Description:

SAM template deployment error for conditional Lambda function url (Unresolved resource dependencies).

When the SAM templates contains a Lambda that is declared as a conditional resource, and has the property set for FunctionUrlConfig, and the condition is not satisfied on deployment, the deployment fails.

Steps to reproduce:

Use a SAM template, with a conditional Lambda function resource declared. Add the FunctionUrlConfig property to the Lambda. Deploy the template with parameters that do not satisfy the condition.

A minimal example template:

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Test conditionalFunctionUrlConfig
Parameters:
  Env:
    Type: String
Conditions:
  IsSandbox:
    Fn::Equals:
    - Ref: Env
    - sandbox
Resources:
  ConditionalLambdaFunction:
    Type: AWS::Serverless::Function
    Condition: IsSandbox
    Properties:
      FunctionName:
        Fn::Sub: ${AWS::StackName}-conditional-lambda-function
      Runtime: python3.9
      Handler: index.my_handler
      FunctionUrlConfig:
        AuthType: NONE
      InlineCode:
        ZipFile: "def my_handler(event, context):\n  message = 'Hello World - Conditional\
          \ URL!'\n  return message"
    Metadata:
      SamResourceId: ConditionalLambdaFunction

Commands:

sam deploy --template-file <TEMPLATE_PATH> --parameter-overrides Env=production --debug --stack-name <STACK_NAME>

Observed result:

Initiating deployment
=====================
2022-04-24 16:09:42,855 | Collected default values for parameters: {}
2022-04-24 16:09:42,868 | Sam customer defined id is more priority than other IDs. Customer defined id for resource ConditionalLambdaFunction is ConditionalLambdaFunction
2022-04-24 16:09:42,868 | 1 stacks found in the template
2022-04-24 16:09:42,868 | Collected default values for parameters: {}
2022-04-24 16:09:42,881 | Sam customer defined id is more priority than other IDs. Customer defined id for resource ConditionalLambdaFunction is ConditionalLambdaFunction
2022-04-24 16:09:42,881 | 1 resources found in the stack 
2022-04-24 16:09:42,881 | Collected default values for parameters: {}
2022-04-24 16:09:42,894 | Sam customer defined id is more priority than other IDs. Customer defined id for resource ConditionalLambdaFunction is ConditionalLambdaFunction
2022-04-24 16:09:42,894 | Found Serverless function with name='ConditionalLambdaFunction' and InlineCode
ConditionalLambdaFunction Function Url may not have authorization defined.
2022-04-24 16:09:43,711 | Stack with id test does not exist

Waiting for changeset to be created..
2022-04-24 16:09:50,331 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': '4cd815a7-bad0-42f4-8990-5612437f5c0c', 'installationId': '525682af-4356-4f26-96da-aa3b43f7c9ec', 'sessionId': '7f501869-84f3-42b9-a400-aa89db93e6e3', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.8.13', 'samcliVersion': '1.46.0', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam deploy', 'metricSpecificAttributes': {'projectType': 'CFN'}, 'duration': 7894, 'exitReason': 'ChangeSetError', 'exitCode': 1}}]}
2022-04-24 16:09:51,005 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)
Error: Failed to create changeset for the stack: test, ex: Waiter ChangeSetCreateComplete failed: Waiter encountered a terminal failure state: For expression "Status" we matched expected path: "FAILED" Status: FAILED. Reason: Template format error: Unresolved resource dependencies [ConditionalLambdaFunction] in the Resources block of the template

Expected result:

The changset should be created successfully and deployment should proceed.

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

  1. OS: macOS Monterey, 12.3.1
  2. If using SAM CLI, sam --version: SAM CLI, version 1.46.0
  3. AWS region: us-west-2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions