Git Product home page Git Product logo

Comments (37)

sanathkr avatar sanathkr commented on May 18, 2024 6

We have just pushed support for Intrinsic functions - https://github.com/awslabs/serverless-application-model/blob/master/HOWTO.md#using-intrinsic-functions

It should work everywhere except for the caveats mentioned in the above doc. If you find any scenario where it doesn't work, please create a new bug.

!Sub "Thanks everyone for the awesome feedback. ${your_username} are awesome!"

from serverless-application-model.

stuartstevenson avatar stuartstevenson commented on May 18, 2024 3

I've been having this issue with Fn::ImportValue for the ::Api Variables property to be able to pass in the function arn.

Is this bug fix to support all of the intrinsic functions?

from serverless-application-model.

sanathkr avatar sanathkr commented on May 18, 2024 2

I am sorry you are running into the bug. Unfortunately there are no workarounds besides switching to regular AWS::Lambda::Function resource.

We are actively working on fixing it. Will let you know once its done

from serverless-application-model.

sanathkr avatar sanathkr commented on May 18, 2024 2

@stuartstevenson #20 was a bug that was fixed. You should be able to use any Fn:: function with Variables property. However you cannot pass the ARN directly to your Swagger. It doesn't work. You should pass function name and construct the ARN there. See this example: https://github.com/awslabs/serverless-application-model/blob/master/examples/2016-10-31/api_swagger_cors/swagger.yaml#L23

from serverless-application-model.

sanathkr avatar sanathkr commented on May 18, 2024 2

Thanks for the comment. Yes, we will support this usecase as well...

from serverless-application-model.

aaronp-hd avatar aaronp-hd commented on May 18, 2024 2

I ended up with something like this:

Conditions:
  RunLocally:
    Fn::Equals:
      - Ref: pEnvironment
      - "local"

And then:

  MyFunction:
    Type: "AWS::Serverless::Function"
    Properties:
      CodeUri:
        Fn::If:
          - RunLocally
          - "../../../build/distributions/myfunction.zip"
          -
            Bucket: pMyFunctionS3BucketName
            Key: pMyFunctionS3BucketKey

from serverless-application-model.

stuartstevenson avatar stuartstevenson commented on May 18, 2024 1

@sanathkr Thank you for your response. Is there a reason why ARNs in particular cannot be passed as I had made the assumption that the stage variable was just a string i was setting? I would not have assumed that the contents of the string would be validated.

from serverless-application-model.

brettstack avatar brettstack commented on May 18, 2024 1

I'm still getting this error when trying to use !ImportValue for AWS::Serverless::Function

Resources:
  LambdaFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: bundle.handler
      MemorySize: 128
      Runtime: nodejs4.3
      Timeout: 3
      Events:
        List:
          Type: Api
          Properties:
            RestApiId: !ImportValue API-ApiId
            Path: /users
            Method: GET

from serverless-application-model.

jolexa avatar jolexa commented on May 18, 2024 1

Our org would also like to see !Ref supported in a the CodeUri field of a AWS::Serverless::Function in addition to the proposed items in the original comment.

Something like this, is what we are thinking (idolized design):

      CodeUri:
        Fn::Join:
          - '-'
          - - s3://some-known-convention
            - Ref: AWS::AccountId
            - '/github-sha/deployment.zip'

from serverless-application-model.

deathbob avatar deathbob commented on May 18, 2024

Trying to use !GetAtt for SecurityGroupIds in a VpcConfig section of a Lambda, get Type of property 'VpcConfig' is invalid.

Works fine when I manually look up the values and plug in the strings, so figure it must be this same issue.

Timeframe on a fix? Any workarounds possible?

Loving the new SAM stuff but this is a deal-breaker.

from serverless-application-model.

joekiller avatar joekiller commented on May 18, 2024

Fn::Import wasn't working for.me earlier today. Can you all confirm that it is fixed? I can create an example if necessary.

from serverless-application-model.

sanathkr avatar sanathkr commented on May 18, 2024

Can you give me an example with the error you received?

from serverless-application-model.

joekiller avatar joekiller commented on May 18, 2024

I'll create one tomorrow and post here.

from serverless-application-model.

joekiller avatar joekiller commented on May 18, 2024

I was using multiple short form functions in a row which is not supported. So trying

Resource: !ImportValue !Sub '${KMSKey}-blah'

Is improper while

Resource: !ImportValue 
                      'Fn::Sub': '${KMSKey}-blah'

Works. http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-base64.html Notes the problem I had.

from serverless-application-model.

weargoggles avatar weargoggles commented on May 18, 2024

I'm experiencing a variation of this trying to use !Ref as a value in a Function's Environment. Is my only option to switch to AWS::Lambda::Function for now?

Edit: I had a typo in my CodeUri attribute and that caused "internal error in transform" which led me here. Sorry.

from serverless-application-model.

sanathkr avatar sanathkr commented on May 18, 2024

!Ref in environment variables is supposed to work out-of-box. Can you post an example?

from serverless-application-model.

weargoggles avatar weargoggles commented on May 18, 2024

It did work. I was mistaken.

from serverless-application-model.

dinvlad avatar dinvlad commented on May 18, 2024

Interestingly, many of the intrinsics work through CodePipeline action for CloudFormation. Is that case handled differently?

from serverless-application-model.

judahb avatar judahb commented on May 18, 2024

Just curious, when is this available? Is it currently available in AWS::Serverless-2016-10-31?

from serverless-application-model.

joekiller avatar joekiller commented on May 18, 2024

from serverless-application-model.

baechul avatar baechul commented on May 18, 2024

I am trying to do something like this to enable both local and CI run but doesn't work:
CodeUri:
!If
- CreateDevEnvironment
- ../../../target/helloworld-1.0-SNAPSHOT.jar
-
Bucket: !Ref BucketName
Key: !Ref CodeKey
Is If intrinsic function supported? Or how I can switch between 2 different objects (string and S3 location object) for CodeUrl in the same template?

from serverless-application-model.

MaiKaY avatar MaiKaY commented on May 18, 2024

Dont know if If intrinsic functions are supported but an alternative would be to pass BucketName and Key as a parameter into your CF template.

from serverless-application-model.

baechul avatar baechul commented on May 18, 2024

@MaiKaY Thanks. But in may case, I use a S3 location with BucketName and Key for CI. For local with "sam local", my CodeUri value should be "./../../target/helloworld-1.0-SNAPSHOT.jar", which is a string type.

from serverless-application-model.

aaronp-hd avatar aaronp-hd commented on May 18, 2024

This is exactly what I'm trying to do as well but I haven't yet been able to find a way around this -- surely this must be a reasonably common use case? I too would like to switch CodeUri conditionally depending on if I'm running locally or not. If running locally CodeUri should be a String, but if not I need a S3 location with bucket name and key.

Are there any plans to support the If intrinsic function, or are there any other ways to achieve this?

from serverless-application-model.

bluepeter avatar bluepeter commented on May 18, 2024

@eelixa did you try using the full name for the intrinsic function, versus the shorthand notation? For SAM my understanding is you must use the former.

from serverless-application-model.

aaronp-hd avatar aaronp-hd commented on May 18, 2024

@bluepeter Ah right, I didn't realise that was the case. I have the If part working now. Thanks a lot for your help!

from serverless-application-model.

MaiKaY avatar MaiKaY commented on May 18, 2024

@eelixa would be cool if you can paste your working code here. To avoid similar issues in the future :-)

from serverless-application-model.

bluepeter avatar bluepeter commented on May 18, 2024

You cannot use the shorthand notation in SAM. Please use, e.g., Fn::Join and Ref instead. See the discussion above in this very issue.

from serverless-application-model.

joshuahiggins avatar joshuahiggins commented on May 18, 2024

Sorry, removed my prior comment on accident. For anyone confused by @bluepeter's reply to seemingly no-one, I posted about the an API event in an AWS:Serverless:Function with a path of !Join [ !Ref ApiBaseUrl, /something ] failing to transform on CloudFormation, but running fine in aws-sam-local and validating locally.

Anyway, I do not see anyone mentioning that shorthand isn't supported except you. The documentation doesn't mention it either, and the pending documentation update (#290) indicates that Events in AWS:Serverless:Function should support all intrinsic functions. Our team is using the same !Join & !Ref shorthand combo as above to set Policies and some other values in our serverless functions without issue, so that's why I'm surprised to hit a wall with Path.

from serverless-application-model.

sanathkr avatar sanathkr commented on May 18, 2024

With Path property of Events structure, SAM needs to insert the value of this property into Swagger as a key of a dictionary like this:

{
  "paths": {
     "<Value of Path property>": {...}
  }
}

Since SAM runs "before" any intrinsic functions are processed, it has no way of getting the path string that you expect to be obtained by resolving the intrinsics. SAM works around this problem in most cases by carefully passing the value (containing intrinsics) directly to the next stage of processing that deploys the stack. In case of Path, we need cannot insert an intrinsic function as a key of a dictionary. Therefore SAM gives up and fails. Policies, on the other hand, are never entirely resolved in SAM. They are passed through directly to the next layer if SAM finds an intrinsic function there.

from serverless-application-model.

joshuahiggins avatar joshuahiggins commented on May 18, 2024

Good to know. Thanks for the detailed info.

from serverless-application-model.

anandchristal avatar anandchristal commented on May 18, 2024

in usage plan defintion AWS::ApiGateway::UsagePlan...not able to refer stage name from AWS::Serverless::Api...getting into race situation the usageplan ran ahead of api/stage creation...event i marked dependson:api resource for usageplan resource...but still it is not working

from serverless-application-model.

brunofitas avatar brunofitas commented on May 18, 2024

Hi guys.
I still have problems with Fn::ImportValue and SAM Local.
The following deploys but I'm unable to invoke it locally.

Environment:
  Variables:
    TOPIC_ARN:
       Fn::ImportValue:
         !Sub "${AlarmNotificationTopicStackName}-TopicName"

Any ideas?
Thanks

from serverless-application-model.

weargoggles avatar weargoggles commented on May 18, 2024

from serverless-application-model.

weargoggles avatar weargoggles commented on May 18, 2024

from serverless-application-model.

OGoodness avatar OGoodness commented on May 18, 2024

what's the most recent issue related to this? So that my team can track this issue.

from serverless-application-model.

hoffa avatar hoffa commented on May 18, 2024

@OGoodness I've created the #2533 meta-issue to track intrinsic function-related problems

from serverless-application-model.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.