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

(assets, aws-lambda): Add asset metadata for nested stack and image-type Lambda Function #14593

Closed
1 of 2 tasks
hawflau opened this issue May 7, 2021 · 3 comments · Fixed by #17293 or #17368
Closed
1 of 2 tasks
Labels
@aws-cdk/assets Related to the @aws-cdk/assets package @aws-cdk/aws-lambda Related to AWS Lambda effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p1

Comments

@hawflau
Copy link

hawflau commented May 7, 2021

Add CloudFormation resource metadata for SAM to find local assets for the resources below:

  1. local nested stack
  2. image-type Lambda Function

Use Case

In this PR, resource metadata was added for zip-type Lambda Function for SAM to find local assets (for example, for running sam local invoke). As SAM CLI now supports local nested stacks and image-type Lambda Function, adding resource metadata for these two types of resources will enable SAM CLI to support CDK-synthed templates with these two types of resources.

Proposed Solution

I believe the implementation will be very similar to the PR mentioned above.
For local nested stack, the value of aws::asset::property should be "TemplateURL".
For image-type Lambda Function, it's a bit tricky - because the local path has to sit inside the ImageUri property under Code, I propose the value of aws::asset::property to be "Code.ImageUri".

Example for local nested stack (in yaml):

nestedstackNestedStacknestedstackNestedStackResource71CDD241:
    Type: AWS::CloudFormation::Stack
    Properties:
      TemplateURL:
        Fn::Join:
          - ""
          - - https://s3.
            - Ref: AWS::Region
            - "."
            - Ref: AWS::URLSuffix
            - /
            - Ref: AssetParameters8cb8f69d88bba4ff29b6cfb1808b58a5d4b721166d137c367a744f8b6e5e65bfS3BucketFD698EA9
            - /
            - Fn::Select:
                - 0
                - Fn::Split:
                    - "||"
                    - Ref: AssetParameters8cb8f69d88bba4ff29b6cfb1808b58a5d4b721166d137c367a744f8b6e5e65bfS3VersionKey60183D77
            - Fn::Select:
                - 1
                - Fn::Split:
                    - "||"
                    - Ref: AssetParameters8cb8f69d88bba4ff29b6cfb1808b58a5d4b721166d137c367a744f8b6e5e65bfS3VersionKey60183D77
      Parameters:
        # ...
    UpdateReplacePolicy: Delete
    DeletionPolicy: Delete
    Metadata:
      aws:cdk:path: root-stack/nested-stack.NestedStack/nested-stack.NestedStackResource
      aws:asset:path: rootstacknestedstackACD02B51.nested.template.json # <- new
      aws:asset:property: TemplateURL # <- new

Example for image-type Lambda Function (in yaml):

containerfunction2D259B7A:
    Type: AWS::Lambda::Function
    Properties:
      Code:
        ImageUri:
          Fn::Join:
            - ""
            - - Ref: AWS::AccountId
              - .dkr.ecr.
              - Ref: AWS::Region
              - "."
              - Ref: AWS::URLSuffix
              - /aws-cdk/assets:58ff0b9a5ea87b6462d9a416b6066e346ae4b60f8f7ec6018972f50867181a9c
      Role:
        Fn::GetAtt:
          - containerfunctionServiceRole5EB80FD7
          - Arn
      ImageConfig:
        Command:
          - app.get
        EntryPoint:
          - /lambda-entrypoint.sh
      PackageType: Image
    DependsOn:
      - containerfunctionServiceRole5EB80FD7
    Metadata:
      aws:cdk:path: root-stack/container-function/Resource
      aws:asset:path: path/to/lambda_code # <- new
      aws:asset:property: Code.ImageUri # <- new

Other

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

@hawflau hawflau added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels May 7, 2021
@github-actions github-actions bot added @aws-cdk/assets Related to the @aws-cdk/assets package @aws-cdk/aws-lambda Related to AWS Lambda labels May 7, 2021
@eladb
Copy link
Contributor

eladb commented May 10, 2021

@hawflau makes total sense to add support for this. I've tagged it as P1, which means it should be on our near-term roadmap.

We welcome community contributions! If you are able, we encourage you to contribute a bug fix or new feature to the CDK. If you decide to contribute, please start an engineering discussion in this issue to ensure there is a commonly understood design before submitting code. This will minimize the number of review cycles and get your code merged faster.

@moelasmar
Copy link
Contributor

Added PR to add Asset metadata to SpecRestApi resource when it contains AssetApiDefinition.

mergify bot pushed a commit that referenced this issue Nov 11, 2021
…al tooling (#17343)

----
Reference issue #14593
Building on this initial PR: #1433

We're looking to add asset metadata to the NestedStack resource. The implementation is similar to this one [design/code-asset-metadata.md](https://github.com/aws/aws-cdk/pull/design/code-asset-metadata.md). This will allow SAM CLI to support CDK-synthed templates nested function resources.

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@mergify mergify bot closed this as completed in #17293 Nov 11, 2021
mergify bot pushed a commit that referenced this issue Nov 11, 2021
)

Adds Assets metadata to RestApi resource in case if AssetApiDefinition is used. This Metadata will enable SAM
CLI to find local assets used by RestApi in the template.

It follows the same design in document [design/code-asset-metadata.md](https://github.com/aws/aws-cdk/pull/design/code-asset-metadata.md)

Fixes #14593

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

mergify bot pushed a commit that referenced this issue Nov 15, 2021
)

Adds asset metadata to image-type lambda functions. This will allow SAM CLI to support local invocation of image-type lambdas from CDK-synthed templates.

It follows the same design and builds upon #1433

Fixes #14593

Uses some changes from #17293 to enable asset metadata generation in integration tests

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
mpvosseller pushed a commit to mpvosseller/aws-cdk that referenced this issue Nov 16, 2021
…#17368)

Adds asset metadata to image-type lambda functions. This will allow SAM CLI to support local invocation of image-type lambdas from CDK-synthed templates.

It follows the same design and builds upon aws#1433

Fixes aws#14593

Uses some changes from aws#17293 to enable asset metadata generation in integration tests

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
mergify bot pushed a commit that referenced this issue Nov 19, 2021
… resource provider functions (#17551)

----
Following up on issue #14593 and PR #1433. 
It seems that log retention and customer resource provider constructs create the corresponding lambda functions using ```CfnResource()``` which means that the asset metadata isn't appended to the output template. 

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
mergify bot pushed a commit that referenced this issue Nov 19, 2021
Following up on issue #14593

The integration with SAM tool requires to have some more info about the Assets. SAM needs to know if the Asset was already bundled or not, and what is the original asset path before staging.

This change is to add the following assets metadata:
 - aws:asset:is-bundled 
 - aws:asset:original-path

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this issue Feb 21, 2022
…al tooling (aws#17343)

----
Reference issue aws#14593
Building on this initial PR: aws#1433

We're looking to add asset metadata to the NestedStack resource. The implementation is similar to this one [design/code-asset-metadata.md](https://github.com/aws/aws-cdk/pull/design/code-asset-metadata.md). This will allow SAM CLI to support CDK-synthed templates nested function resources.

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this issue Feb 21, 2022
…#17293)

Adds Assets metadata to RestApi resource in case if AssetApiDefinition is used. This Metadata will enable SAM
CLI to find local assets used by RestApi in the template.

It follows the same design in document [design/code-asset-metadata.md](https://github.com/aws/aws-cdk/pull/design/code-asset-metadata.md)

Fixes aws#14593

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this issue Feb 21, 2022
…#17368)

Adds asset metadata to image-type lambda functions. This will allow SAM CLI to support local invocation of image-type lambdas from CDK-synthed templates.

It follows the same design and builds upon aws#1433

Fixes aws#14593

Uses some changes from aws#17293 to enable asset metadata generation in integration tests

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this issue Feb 21, 2022
… resource provider functions (aws#17551)

----
Following up on issue aws#14593 and PR aws#1433. 
It seems that log retention and customer resource provider constructs create the corresponding lambda functions using ```CfnResource()``` which means that the asset metadata isn't appended to the output template. 

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this issue Feb 21, 2022
Following up on issue aws#14593

The integration with SAM tool requires to have some more info about the Assets. SAM needs to know if the Asset was already bundled or not, and what is the original asset path before staging.

This change is to add the following assets metadata:
 - aws:asset:is-bundled 
 - aws:asset:original-path

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/assets Related to the @aws-cdk/assets package @aws-cdk/aws-lambda Related to AWS Lambda effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p1
Projects
None yet
4 participants