aws / aws/aws-sam-cli

Bug: SAM Conditional Globals Environment Variables maps fail to merge with Function environment variables

Đang mở
#8,167 2 bình luận 0 reaction 0 người được giao Xem trên GitHub
maintainer/need-response stage/needs-triage
Ngôn ngữ chính
Python
Star
6.7k
Fork
1.2k
Merge trung bình
1 ngày 10 giờ
Pull request đã merge (30 ngày)
52

Mô tả

### Description:
Defect where conditional Global environment variables fail to merge properly to Function.
[This example demonstrates a defect in AWS SAM where conditional environment variables defined in the `Globals.Function.Environment.Variables` section using `!If` statements do not properly merge into individual `AWS::Serverless::Function` resources that have their own `Environment.Variables` section.](https://github.com/prower-turnitin/sam-conditional-globals-example/tree/main#)

### Steps to reproduce:

Deploy the linked https://github.com/prower-turnitin/sam-conditional-globals-example/tree/main# SAM App.
You'll see function2 does not merge Global Environment as described : https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-specification-template-anatomy-globals.html

### Observed result:

When conditional statements (`!If`) are used in the Globals section, the conditional environment variables are **NOT** merged into functions that have their own Environment.Variables section.

### Expected result:

According to AWS SAM documentation, global environment variables should merge with function-specific environment variables, with function-specific variables taking precedence when there are conflicts.

### Function1 (No function-specific environment variables)
✅ **WORKS CORRECTLY** - Receives all conditional global variables:
```json
{
"LOG_LEVEL": "INFO",
"log_level": "INFO",
"OTEL_INSTRUMENTATION_COMMON_DEFAULT_ENABLED": "false",
"OTEL_SERVICE_NAME": "sam-conditional-example-dev"
}
```

### Function2 (Has function-specific environment variables)
❌ **DEFECT DEMONSTRATED** - Missing conditional global variables:
```json
{
"LOG_LEVEL": "DEBUG", // Function-specific override (correct)
"FUNCTION_SPECIFIC_VAR": "function2-value", // Function-specific (correct)
"CUSTOM_CONFIG": "enabled" // Function-specific (correct)
// MISSING: OTEL_INSTRUMENTATION_COMMON_DEFAULT_ENABLED
// MISSING: OTEL_SERVICE_NAME
// MISSING: log_level
}
```

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

1. OS: Darwin NOA-M-JW3FNV5R6Y 24.5.0 Darwin Kernel Version 24.5.0: Tue Apr 22 19:53:27 PDT 2025; root:xnu-11417.121.6~2/RELEASE_ARM64_T6041 arm64

2. `sam --version`: SAM CLI, version 1.137.1
3. AWS region: us-east-2

```
# Paste the output of `sam --info` here
{
"version": "1.137.1",
"system": {
"python": "3.11.10",
"os": "macOS-15.5-arm64-arm-64bit"
},
"additional_dependencies": {
"docker_engine": "Not available",
"aws_cdk": "Not available",
"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_PACKAGE_PERFORMANCE",
"SAM_CLI_BETA_RUST_CARGO_LAMBDA"
]
}

```

`Add --debug flag to command you are running`

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Bắt đầu với ứng dụng SAM sam-conditional-globals-example được liên kết và tái hiện quá trình triển khai bằng SAM CLI 1.137.1. So sánh Function1 và Function2 với tài liệu AWS SAM về việc hợp nhất các biến toàn cục; hoàn thành khi Function2 vẫn giữ các ghi đè dành riêng cho hàm của nó, đồng thời cũng nhận được các biến toàn cục có điều kiện.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
aws, python
Lĩnh vực
cloud
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
45/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.