serverless-application-model icon indicating copy to clipboard operation
serverless-application-model copied to clipboard

AWS::Serverless::Application Location string cannot be set from Substitution

Open karlkyck opened this issue 6 years ago • 9 comments

We are using AWS::Serverless::Application to break up our CloudFormation into smaller pieces. We would like to use the Substitution function to define the Location of the CloudFormation template:

MyApplication:
    Type: AWS::Serverless::Application
    Properties:
      Location: !Sub 'https://s3.eu-west-1.amazonaws.com/${MyApplicationTemplate}'

This results in:

Failed to create the changeset: Waiter ChangeSetCreateComplete failed: Waiter encountered a terminal failure state Status: FAILED. Reason: Transform AWS::Serverless-2016-10-31 failed with: Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyApplication] is invalid. Resource is missing the required [ApplicationId] property.

Is this something will be supported soon?

karlkyck avatar Dec 02 '18 10:12 karlkyck

Good callout. It'd definitely be nice to support intrinsic functions in the case where the Location property is being used as an S3 template URL and not a reference to a SAR app. The change would go in this area if you want to submit a PR:

https://github.com/awslabs/serverless-application-model/blob/develop/samtranslator/plugins/application/serverless_app_plugin.py#L78-L85

jlhood avatar Dec 04 '18 17:12 jlhood

I got similar issue

    Type: AWS::Serverless::Application
    Properties:
      Location:
        ApplicationId: !Sub "arn:aws:serverlessrepo:${AWS::Region}:123456789012:applications/app-name"

And I got Transform AWS::Serverless-2016-10-31 failed with: Internal transform failure.

pahud avatar Feb 18 '19 12:02 pahud

I believe I ran into the same/similar bug with more descriptive error. I'm using FindInMap intrinsic function for resolving ApplicationId property of AWS::Serverless::Application.

Here's error message and resource definition (stack trace available on the bottom):

raise InvalidDocumentException(document_errors)
samtranslator.model.exceptions.InvalidDocumentException: 
[InvalidResourceException('CertificateFactoryCertificates', "Property 'ApplicationId' cannot be resolved. Only FindInMap and Ref intrinsic functions are supported.")]
CertificateFactoryCertificates:
    Type: AWS::Serverless::Application
    Properties:
      Location:
        ApplicationId: !FindInMap [ "Environment", !Ref Environment, "SARApplicationId" ]
        SemanticVersion: !Ref CertificateFactoryVersion

Traceback:

Traceback (most recent call last):
  File "D:\obj\windows-release\37amd64_Release\msi_python\zip_amd64\runpy.py", line 193, in _run_module_as_main
  File "D:\obj\windows-release\37amd64_Release\msi_python\zip_amd64\runpy.py", line 85, in _run_code
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\__main__.py", line 12, in <module>
    cli(prog_name="sam")
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 782, in main
    rv = self.invoke(ctx)
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\decorators.py", line 73, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\telemetry\metrics.py", line 148, in wrapped
    raise exception  # pylint: disable=raising-bad-type
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\telemetry\metrics.py", line 114, in wrapped
    return_value = func(*args, **kwargs)
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\commands\build\command.py", line 129, in cli
    mode,
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\commands\build\command.py", line 179, in do_cli
    mode=mode,
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\commands\build\build_context.py", line 62, in __enter__
    self._function_provider = SamFunctionProvider(self._template_dict, self._parameter_overrides)
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\providers\sam_function_provider.py", line 40, in __init__
    self.template_dict = SamFunctionProvider.get_template(template_dict, parameter_overrides)
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\providers\sam_base_provider.py", line 126, in get_template
    template_dict = SamTranslatorWrapper(template_dict, parameter_values=parameters_values).run_plugins()
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\samlib\wrapper.py", line 79, in run_plugins
    functools.reduce(lambda message, error: message + " " + str(error), e.causes, str(e))
samcli.commands.validate.lib.exceptions.InvalidSamDocumentException: [InvalidResourceException('CertificateFactoryCertificates', "Property 'ApplicationId' cannot be resolved. Only FindInMap and Ref intrinsic functions are supported.")] ('CertificateFactoryCertificates', "Property 'ApplicationId' cannot be resolved. Only FindInMap and Ref intrinsic functions are supported.")

vtuhtan avatar Nov 20 '20 12:11 vtuhtan

Any idea why there is no traction on this? My use case is as shown below (don't want to create secondary buckets but re-use),

  DataBucket:
    Type: "AWS::Serverless::Application"
    Properties:
      Location:
        !If [
          IsReplica,
          "s3.secondary.template.yaml", <== Wont create the bucket, but just update the SSM based on 'PrimaryRegion' params
          "s3.primary.template.yaml", <== Create the bucket, create DR bucket and setup replication...
        ]
      Parameters:
        Primary: !Ref PrimaryRegion

aczire avatar Feb 23 '21 17:02 aczire

Anyone knows why https://github.com/aws/serverless-application-model/pull/710 has been closed without merging? @jlhood @keetonian ? thanks

Leooo avatar Mar 11 '21 18:03 Leooo

For anyone who is blocked here without support from AWS:

Beware of this bug, where you cannot publish a stack containing a substitution for a nested stack's SemanticVersion. That means that you cannot use deeply nested dynamic stacks, in the sense that the child nested stack could not consume a dynamic version of the grandchild.

Leooo avatar May 11 '21 15:05 Leooo

Kind of surprising that one cannot do a simple regional find in map (still, issues are 2+ years old), like we do with ec2 amis

Our use case involves a private SAR app published regionally (because it contains IAM features and regional boundary items). So this code should work but does not for ApplicationId arn

Mappings:

  SarArn:
    RegionMap:
      us-west-2: arn:aws:serverlessrepo:us-west-2:<account-id>:applications/rtorpo
      us-east-1: arn:aws:serverlessrepo:us-east-1:<account-id>:applications/rtorpo

Resources:

  RTORPO:
    Type: AWS::Serverless::Application
    Properties:
      Location:
        ApplicationId: !FindInMap [SarArn, RegionMap, !Ref AWS::Region]
        SemanticVersion: !Ref RTOVersionTarget
samcli.commands.validate.lib.exceptions.InvalidSamDocumentException: [InvalidResourceException('RTORPO', "Property 'ApplicationId' cannot be resolved. Only FindInMap and Ref intrinsic functions are supported.")] ('RTORPO', "Property 'ApplicationId' cannot be resolved. Only FindInMap and Ref intrinsic functions are supported.")
make: *** [deploy] Error 1

rojomisin avatar Jul 15 '21 18:07 rojomisin

@rojomisin what have you done to solve that scenario? I have the same issue.

I cannot understand why this is not working, even when the error message says that FindInMap and Ref are supported.

Is there somebody from the SAM team that can guide us with something?

afllanos avatar Jul 22 '21 17:07 afllanos

Any traction on this issue???

SpyderDave avatar Jan 10 '22 12:01 SpyderDave

You might be able to get this to work by adding AWS::LanguageExtensions to Transform as such:

Transform:
  - AWS::LanguageExtensions
  - AWS::Serverless-2016-10-31

AWS::LanguageExtensions resolves intrinsic functions if the value is known when Transforms are run.

See https://github.com/aws/serverless-application-model/issues/2533 for more information.

hoffa avatar Oct 17 '22 21:10 hoffa

Closing in favor of https://github.com/aws/serverless-application-model/issues/2533.

hoffa avatar Nov 03 '22 23:11 hoffa

@hoffa's advice above, to use AWS::LanguageExtensions, helped in the use case of using Fn::Sub when specifying a value for the Location.ApplicationId property. Thanks for mentioning that.

    Type: AWS::Serverless::Application
    Properties:
      Location:
        ApplicationId: !Sub arn:${AWS::Partition}:serverlessrepo:${AWS::Region}:${AWS::AccountId}:applications/${AppName}
        SemanticVersion: !Ref AppVersion

rhbecker avatar Jun 17 '23 04:06 rhbecker