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

bugfix/integrate_intrinsics #1343

Merged
merged 9 commits into from
Aug 16, 2019

Conversation

viksrivat
Copy link
Contributor

Issue #, if available:
There was a bug when dealing with layers and intrinsics. This is an update to add tests and to address it.
Description of changes:

Checklist:

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

When running local layer integration tests, there was a cleanup error that
occured if there was a KeyboardExit occurred on the previous run.
This causes problems with cached values on consecutive tests.
When running local layer integration tests, there was a cleanup error that
occured if there was a KeyboardExit occurred on the previous run.
This causes problems with cached values on consecutive tests.
Lambda Layers were added as a special case where Ref's to unresolved resources remained as {"Ref": logical_id}.
This was chosen to be the default since SamTranslator handles the translation of some resource and converts some types such as
{"Ref":"AWS::Region"} -> {"Ref": "us-east-1"} and replacing Globals.
@viksrivat
Copy link
Contributor Author

The integrate_intrinsics pr failed because LambdaLayers were handling Refs in a different way than the default resolver. I now handle LambdaLayers as a special case since unresolved Refs become {"Ref": "logical_id"}.

Before: SamTranslator was run and left attributes such as {"Ref": "value"} -> {"Ref": "value"}. The translator would leave the following resource as is.

StageTest:
     Properties:
          RestApiId: !Ref Value

However, we need to resolve these attributes in order to fully resolve intrinsics. After running a pass through the SamTranslator then IntrinsicResolver. Now, what we do is convert it to

StageTest:
     Properties:
          RestApiId: Value

This is because SamTranslator resolves a ref such as {"Ref": "AWS::Region"} to {"Ref": "us-east-1"}. It also replaces Global Attributes directly into the relevant resources. However, we want {"Ref": "AWS::Region"} to become "us-east-1". Thus, by default we take {"Ref": "value"} -> "value".

To provide support for the special LambdaLayer case, I extended the IntrinsicSymbolTable to use

        {
            "AWS::ApiGateway::RestApi": {
                "RootResourceId": "/"  # It usually used as a reference to the parent id of the RestApi,
            },
            "AWS::Lambda::LayerVersion": {
                IntrinsicResolver.REF: lambda logical_id: {IntrinsicResolver.REF: logical_id}
            },
            "AWS::Serverless::LayerVersion": {
                IntrinsicResolver.REF: lambda logical_id: {IntrinsicResolver.REF: logical_id}
            }
        }

In terms of dealing and managing intrinsics cases such as this, this implementation is not inclusive of all ways to process Refs and Fn::GetAtt. There doesn't seem to be a good standard that CloudFormation has set for all Refs and Fn::GetAtts. We need to either add special support for more types as time goes on or find another way to deal with maintaining intrinsics in the longer term.

@sriram-mv sriram-mv self-requested a review August 16, 2019 22:51
Copy link
Contributor

@sriram-mv sriram-mv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix @viksrivat!

@sriram-mv sriram-mv merged commit 9c0cfd3 into aws:develop Aug 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants