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

Bug: parsing Ref in template.json is incorrect #7413

Closed
axot opened this issue Aug 27, 2024 · 3 comments
Closed

Bug: parsing Ref in template.json is incorrect #7413

axot opened this issue Aug 27, 2024 · 3 comments
Labels
area/intrinsics Ref, If, Sub, GetAtt, ... area/local blocked/close-if-inactive Blocked for >14 days with no response, will be closed if still inactive after 7 days

Comments

@axot
Copy link

axot commented Aug 27, 2024

Description:

sam can't parse the Ref key in the following Lambda definition. We expected TABLE_NAME to be the actual DynamoDB table name, but instead got demogametable2FE33C07.

  "GameHandler295CCC0B": {
   "Type": "AWS::Lambda::Function",
   "Properties": {
    "Code": {
     "S3Bucket": {
      "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-ap-northeast-1"
     },
     "S3Key": "2160ee90758ba745c338833566ade881a8ad5ff3693dcd6d9347e5fdb41b5da4.zip"
    },
    "Environment": {
     "Variables": {
      "TABLE_NAME": {
       "Ref": "demogametable2FE33C07"
      }
     }
    },

Steps to reproduce:

cdk python code as following

        # Create the Lambda function to receive the request
        api_hanlder = lambda_.Function(
            self,
            "GameHandler",
            function_name="game_handler",
            runtime=lambda_.Runtime.PYTHON_3_12,
            code=lambda_.Code.from_asset("src/game"),
            handler="index.handler",
            vpc=vpc,
            vpc_subnets=ec2.SubnetSelection(
                subnet_type=ec2.SubnetType.PRIVATE_ISOLATED
            ),
            memory_size=1024,
            timeout=Duration.minutes(5),
        )

        # grant permission to lambda to write to demo table
        demo_table.grant_write_data(api_hanlder)
        api_hanlder.add_environment("TABLE_NAME", demo_table.table_name)

Run local test

cdk synth --no-staging
sam local invoke GameHandler --no-event -t ./cdk.out/GameStack.template.json -e tests/game/event.json

event.json

{
    "body": "{\"year\":\"2023\",\"title\":\"kkkg\",\"id\":\"12\"}"
}

Observed result:

demogametable2FE33C07

Expected result:

real dynamodb table name

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: Mac 14.6.1
  2. sam --version: SAM CLI, version 1.123.0
  3. AWS region: ap-northeast-1
{
  "version": "1.123.0",
  "system": {
    "python": "3.12.5",
    "os": "macOS-14.6.1-arm64-arm-64bit"
  },
  "additional_dependencies": {
    "docker_engine": "24.0.9",
    "aws_cdk": "2.154.1 (build febce9d)",
    "terraform": "1.5.7"
  },
  "available_beta_feature_env_vars": [
    "SAM_CLI_BETA_FEATURES",
    "SAM_CLI_BETA_BUILD_PERFORMANCE",
    "SAM_CLI_BETA_TERRAFORM_SUPPORT",
    "SAM_CLI_BETA_RUST_CARGO_LAMBDA"
  ]
}
@axot axot added the stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. label Aug 27, 2024
@lucashuy
Copy link
Contributor

Hi, this is a current limitation of the intrinsic support within SAM CLI/SAM local capabilities. When deployed, the intrinsic should be resolved correctly. Unfortunately, I do not have a workaround for this. Please let us know if you come across any other issues.

@lucashuy lucashuy added blocked/close-if-inactive Blocked for >14 days with no response, will be closed if still inactive after 7 days area/local area/intrinsics Ref, If, Sub, GetAtt, ... and removed stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels Aug 28, 2024
@hnnasit
Copy link
Contributor

hnnasit commented Sep 16, 2024

Closing the issue as this seems to be a known limitation. Please open a new issue if you have more questions or concerns.

@hnnasit hnnasit closed this as completed Sep 16, 2024
Copy link
Contributor

⚠️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.

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/local blocked/close-if-inactive Blocked for >14 days with no response, will be closed if still inactive after 7 days
Projects
None yet
Development

No branches or pull requests

3 participants