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

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

Closed
karlkyck opened this issue Dec 2, 2018 · 12 comments
Closed
Labels
area/intrinsics Ref, If, Sub, GetAtt, ... area/resource/application contributors/good-first-issue Good first issue for a contributor type/bug

Comments

@karlkyck
Copy link

karlkyck commented Dec 2, 2018

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?

@jlhood
Copy link
Contributor

jlhood commented Dec 4, 2018

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

@pahud
Copy link
Contributor

pahud commented Feb 18, 2019

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.

@vtuhtan
Copy link

vtuhtan commented Nov 20, 2020

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.")

@aczire
Copy link

aczire commented Feb 23, 2021

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

@Leooo
Copy link

Leooo commented Mar 11, 2021

Anyone knows why #710 has been closed without merging? @jlhood @keetonian ? thanks

@Leooo
Copy link

Leooo commented May 11, 2021

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.

@rojomisin
Copy link

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

@afllanos
Copy link

@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?

@SpyderDave
Copy link

Any traction on this issue???

@hoffa
Copy link
Contributor

hoffa commented Oct 17, 2022

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 #2533 for more information.

@hoffa
Copy link
Contributor

hoffa commented Nov 3, 2022

Closing in favor of #2533.

@hoffa hoffa closed this as completed Nov 3, 2022
@rhbecker
Copy link

@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

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, ... area/resource/application contributors/good-first-issue Good first issue for a contributor type/bug
Projects
None yet
Development

No branches or pull requests