Skip to content

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

@hawflau

Description

@hawflau

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/assetsRelated to the @aws-cdk/assets package@aws-cdk/aws-lambdaRelated to AWS Lambdaeffort/smallSmall work item – less than a day of effortfeature-requestA feature should be added or improved.p1

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions