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: sam deploy using --template parameter does not package application properly #7604

Open
tredfield opened this issue Oct 24, 2024 · 3 comments
Labels
area/deploy sam deploy command blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale.

Comments

@tredfield
Copy link

tredfield commented Oct 24, 2024

Description:

Running sam deploy --template template.yml fails to package app appropriately

Steps to reproduce:

  1. Create sam app using "sam init" command and follow steps
  2. Perform "sam build" and "sam deploy". Verify that the API can be called successfully and no errors in function.
  3. Now perform "sam build" and "sam deploy --template template.yml". Test API and check logs of function

Observed result:

Function fails with
"ERROR","message":{"errorType":"ImportModuleError","errorMessage":"Error: Cannot find module 'app'

Expected result:

Packaging of function should be same with or without --template parameter

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

  1. OS: macOS 14.6.1
  2. sam --version: 1.126.0
  3. AWS region: us-west-2
# Paste the output of `sam --info` here

{
"version": "1.126.0",
"system": {
"python": "3.8.20",
"os": "macOS-14.6.1-x86_64-i386-64bit"
},
"additional_dependencies": {
"docker_engine": "Not available",
"aws_cdk": "2.138.0 (build 6b41c8b)",
"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"
]
}

Add --debug flag to command you are running

❯ sam deploy --template template.yml --debug
2024-10-24 15:21:00,669 | Config file location: /Users/travis.redfield/dev/pokemon/sam-node-dd/samconfig.toml                                   
2024-10-24 15:21:00,674 | Loading configuration values from [default.['deploy'].parameters] (env.command_name.section) in config file at        
'/Users/travis.redfield/dev/pokemon/sam-node-dd/samconfig.toml'...                                                                              
2024-10-24 15:21:00,676 | Configuration values successfully loaded.                                                                             
2024-10-24 15:21:00,677 | Configuration values are: {'stack_name': 'sam-node-dd-dev', 'capabilities': 'CAPABILITY_IAM', 'confirm_changeset':    
True, 'resolve_s3': True, 's3_prefix': 'sam-node-dd', 'region': 'us-west-2', 'image_repositories': []}                                          
2024-10-24 15:21:00,736 | Using config file: samconfig.toml, config environment: default                                                        
2024-10-24 15:21:00,737 | Expand command line arguments to:                                                                                     
2024-10-24 15:21:00,737 | --template_file=/Users/travis.redfield/dev/pokemon/sam-node-dd/template.yml --fail_on_empty_changeset                 
--confirm_changeset --on_failure=ROLLBACK --max_wait_duration=60 --stack_name=sam-node-dd-dev --s3_prefix=sam-node-dd --resolve_s3              
--capabilities=['CAPABILITY_IAM']                                                                                                               

                Managed S3 bucket: aws-sam-cli-managed-default-samclisourcebucket-1fo2l63xfmwdy
                A different default S3 bucket can be set in samconfig.toml
                Or by specifying --s3-bucket explicitly.
2024-10-24 15:21:02,159 | No Parameters detected in the template                                                                                
2024-10-24 15:21:02,205 | There is no customer defined id or cdk path defined for resource HelloWorldFunction, so we will use the resource      
logical id as the resource id                                                                                                                   
2024-10-24 15:21:02,206 | There is no customer defined id or cdk path defined for resource ServerlessRestApi, so we will use the resource       
logical id as the resource id                                                                                                                   
2024-10-24 15:21:02,209 | 0 stacks found in the template                                                                                        
2024-10-24 15:21:02,210 | No Parameters detected in the template                                                                                
2024-10-24 15:21:02,239 | There is no customer defined id or cdk path defined for resource HelloWorldFunction, so we will use the resource      
logical id as the resource id                                                                                                                   
2024-10-24 15:21:02,240 | There is no customer defined id or cdk path defined for resource ServerlessRestApi, so we will use the resource       
logical id as the resource id                                                                                                                   
2024-10-24 15:21:02,301 | There is no customer defined id or cdk path defined for resource HelloWorldFunction, so we will use the resource      
logical id as the resource id                                                                                                                   
2024-10-24 15:21:02,303 | Sam customer defined id is more priority than other IDs. Customer defined id for resource HelloWorldFunction is       
HelloWorldFunction                                                                                                                              
2024-10-24 15:21:03,004 | File with same data already exists at sam-node-dd/88604a918d89fdebe227ba16b991f9a5, skipping upload                   

        Deploying with following values
        ===============================
        Stack name                   : sam-node-dd-dev
        Region                       : us-west-2
        Confirm changeset            : True
        Disable rollback             : False
        Deployment s3 bucket         : aws-sam-cli-managed-default-samclisourcebucket-1fo2l63xfmwdy
        Capabilities                 : ["CAPABILITY_IAM"]
        Parameter overrides          : {}
        Signing Profiles             : {}

Initiating deployment
=====================

2024-10-24 15:21:03,046 | No Parameters detected in the template                                                                                
2024-10-24 15:21:03,081 | Sam customer defined id is more priority than other IDs. Customer defined id for resource HelloWorldFunction is       
HelloWorldFunction                                                                                                                              
2024-10-24 15:21:03,082 | There is no customer defined id or cdk path defined for resource ServerlessRestApi, so we will use the resource       
logical id as the resource id                                                                                                                   
2024-10-24 15:21:03,084 | 0 stacks found in the template                                                                                        
2024-10-24 15:21:03,085 | No Parameters detected in the template                                                                                
2024-10-24 15:21:03,117 | Sam customer defined id is more priority than other IDs. Customer defined id for resource HelloWorldFunction is       
HelloWorldFunction                                                                                                                              
2024-10-24 15:21:03,118 | There is no customer defined id or cdk path defined for resource ServerlessRestApi, so we will use the resource       
logical id as the resource id                                                                                                                   
2024-10-24 15:21:03,120 | 2 resources found in the stack                                                                                        
2024-10-24 15:21:04,241 | File with same data already exists at sam-node-dd/9f5589c1ba3ab4d57e30b003f430caa3.template, skipping upload          


Waiting for changeset to be created..

CloudFormation stack changeset
---------------------------------------------------------------------------------------------------------------------------------------------
Operation                           LogicalResourceId                   ResourceType                        Replacement                       
---------------------------------------------------------------------------------------------------------------------------------------------
* Modify                            HelloWorldFunction                  AWS::Lambda::Function               False                             
* Modify                            ServerlessRestApi                   AWS::ApiGateway::RestApi            False                             
---------------------------------------------------------------------------------------------------------------------------------------------


Changeset created successfully. arn:aws:cloudformation:us-west-2:053655145506:changeSet/samcli-deploy1729808464/c36e603d-846a-41b3-bf09-111aa1947b71


Previewing CloudFormation changeset before deployment
======================================================
Deploy this changeset? [y/N]: y

2024-10-24 15:21:36 - Waiting for stack create/update to complete

CloudFormation events from stack operations (refresh every 5.0 seconds)
---------------------------------------------------------------------------------------------------------------------------------------------
ResourceStatus                      ResourceType                        LogicalResourceId                   ResourceStatusReason              
---------------------------------------------------------------------------------------------------------------------------------------------
2024-10-24 15:21:36,704 | Trial # 0 to get the stack sam-node-dd-dev create events                                                              
2024-10-24 15:21:42,061 | Stack Event: {'StackId':                                                                                              
'arn:aws:cloudformation:us-west-2:053655145506:stack/sam-node-dd-dev/91591640-8b1a-11ef-962b-02438722d453', 'EventId':                          
'HelloWorldFunction-UPDATE_IN_PROGRESS-2024-10-24T22:21:40.567Z', 'StackName': 'sam-node-dd-dev', 'LogicalResourceId': 'HelloWorldFunction',    
'PhysicalResourceId': 'sam-node-dd-dev-HelloWorldFunction-nEpjJpxTth56', 'ResourceType': 'AWS::Lambda::Function', 'Timestamp':                  
datetime.datetime(2024, 10, 24, 22, 21, 40, 567000, tzinfo=tzutc()), 'ResourceStatus': 'UPDATE_IN_PROGRESS', 'ResourceProperties':              
'{"Role":"arn:aws:iam::053655145506:role/sam-node-dd-dev-HelloWorldFunctionRole-C8FCtCLCPm0d","Runtime":"nodejs20.x","Timeout":"3","LoggingConfi
g":{"LogFormat":"JSON"},"Handler":"/opt/nodejs/node_modules/datadog-lambda-js/handler.handler","Environment":{"Variables":{"DD_API_KEY_SECRET_AR
N":"arn:aws:secretsmanager:us-west-2:053655145506:secret:cela/datadog_api_key-oHab1s","DD_SITE":"datadoghq.com","DD_LAMBDA_HANDLER":"app.lambdaH
andler","DD_CAPTURE_LAMBDA_PAYLOAD":"false","DD_VERSION":"v1.2.3","DD_FLUSH_TO_LOG":"true","DD_SERVICE":"sam-node-dd","DD_TRACE_ENABLED":"true",
"DD_ENV":"dev","DD_SERVERLESS_LOGS_ENABLED":"true","DD_ENHANCED_METRICS":"true","DD_MERGE_XRAY_TRACES":"false"}},"Code":{"S3Bucket":"aws-sam-cli
-managed-default-samclisourcebucket-1fo2l63xfmwdy","S3Key":"sam-node-dd/88604a918d89fdebe227ba16b991f9a5"},"Layers":["arn:aws:lambda:us-west-2:4
64622532012:layer:Datadog-Node20-x:112","arn:aws:lambda:us-west-2:464622532012:layer:Datadog-Extension:58"],"Tags":[{"Value":"SAM","Key":"lambda
:createdBy"},{"Value":"v0.14.1","Key":"dd_sls_macro"},{"Value":"SAM","Key":"dd_sls_macro_by"}],"Architectures":["x86_64"]}'}                    
2024-10-24 15:21:42,066 | Stack Event: {'StackId':                                                                                              
'arn:aws:cloudformation:us-west-2:053655145506:stack/sam-node-dd-dev/91591640-8b1a-11ef-962b-02438722d453', 'EventId':                          
'554c20f0-9256-11ef-b34f-02d7b4b0cd3f', 'StackName': 'sam-node-dd-dev', 'LogicalResourceId': 'sam-node-dd-dev', 'PhysicalResourceId':           
'arn:aws:cloudformation:us-west-2:053655145506:stack/sam-node-dd-dev/91591640-8b1a-11ef-962b-02438722d453', 'ResourceType':                     
'AWS::CloudFormation::Stack', 'Timestamp': datetime.datetime(2024, 10, 24, 22, 21, 36, 762000, tzinfo=tzutc()), 'ResourceStatus':               
'UPDATE_IN_PROGRESS', 'ResourceStatusReason': 'User Initiated'}                                                                                 
2024-10-24 15:21:42,069 | Stack Event: {'StackId':                                                                                              
'arn:aws:cloudformation:us-west-2:053655145506:stack/sam-node-dd-dev/91591640-8b1a-11ef-962b-02438722d453', 'EventId':                          
'1f016cf0-9254-11ef-8cb0-062f99b53b77', 'StackName': 'sam-node-dd-dev', 'LogicalResourceId': 'sam-node-dd-dev', 'PhysicalResourceId':           
'arn:aws:cloudformation:us-west-2:053655145506:stack/sam-node-dd-dev/91591640-8b1a-11ef-962b-02438722d453', 'ResourceType':                     
'AWS::CloudFormation::Stack', 'Timestamp': datetime.datetime(2024, 10, 24, 22, 5, 46, 674000, tzinfo=tzutc()), 'ResourceStatus':                
'UPDATE_COMPLETE'}                                                                                                                              
2024-10-24 15:21:42,073 | Skip previous event as time_stamp_marker: 2024-10-24 22:05:46.674000 is after the event time stamp: 2024-10-24        
22:05:46.674000+00:00                                                                                                                           
2024-10-24 15:21:42,074 | Exit from the describe event loop                                                                                     
UPDATE_IN_PROGRESS                  AWS::CloudFormation::Stack          sam-node-dd-dev                     User Initiated                    
UPDATE_IN_PROGRESS                  AWS::Lambda::Function               HelloWorldFunction                  -                                 
2024-10-24 15:21:42,075 | Trial # 0 to get the stack sam-node-dd-dev create events                                                              
2024-10-24 15:21:47,378 | Stack Event: {'StackId':                                                                                              
'arn:aws:cloudformation:us-west-2:053655145506:stack/sam-node-dd-dev/91591640-8b1a-11ef-962b-02438722d453', 'EventId':                          
'HelloWorldFunction-UPDATE_IN_PROGRESS-2024-10-24T22:21:40.567Z', 'StackName': 'sam-node-dd-dev', 'LogicalResourceId': 'HelloWorldFunction',    
'PhysicalResourceId': 'sam-node-dd-dev-HelloWorldFunction-nEpjJpxTth56', 'ResourceType': 'AWS::Lambda::Function', 'Timestamp':                  
datetime.datetime(2024, 10, 24, 22, 21, 40, 567000, tzinfo=tzutc()), 'ResourceStatus': 'UPDATE_IN_PROGRESS', 'ResourceProperties':              
'{"Role":"arn:aws:iam::053655145506:role/sam-node-dd-dev-HelloWorldFunctionRole-C8FCtCLCPm0d","Runtime":"nodejs20.x","Timeout":"3","LoggingConfi
g":{"LogFormat":"JSON"},"Handler":"/opt/nodejs/node_modules/datadog-lambda-js/handler.handler","Environment":{"Variables":{"DD_API_KEY_SECRET_AR
N":"arn:aws:secretsmanager:us-west-2:053655145506:secret:cela/datadog_api_key-oHab1s","DD_SITE":"datadoghq.com","DD_LAMBDA_HANDLER":"app.lambdaH
andler","DD_CAPTURE_LAMBDA_PAYLOAD":"false","DD_VERSION":"v1.2.3","DD_FLUSH_TO_LOG":"true","DD_SERVICE":"sam-node-dd","DD_TRACE_ENABLED":"true",
"DD_ENV":"dev","DD_SERVERLESS_LOGS_ENABLED":"true","DD_ENHANCED_METRICS":"true","DD_MERGE_XRAY_TRACES":"false"}},"Code":{"S3Bucket":"aws-sam-cli
-managed-default-samclisourcebucket-1fo2l63xfmwdy","S3Key":"sam-node-dd/88604a918d89fdebe227ba16b991f9a5"},"Layers":["arn:aws:lambda:us-west-2:4
64622532012:layer:Datadog-Node20-x:112","arn:aws:lambda:us-west-2:464622532012:layer:Datadog-Extension:58"],"Tags":[{"Value":"SAM","Key":"lambda
:createdBy"},{"Value":"v0.14.1","Key":"dd_sls_macro"},{"Value":"SAM","Key":"dd_sls_macro_by"}],"Architectures":["x86_64"]}'}                    
2024-10-24 15:21:47,383 | Skip previous event as time_stamp_marker: 2024-10-24 22:21:40.567000 is after the event time stamp: 2024-10-24        
22:21:40.567000+00:00                                                                                                                           
2024-10-24 15:21:47,384 | Exit from the describe event loop                                                                                     
2024-10-24 15:21:47,385 | Trial # 0 to get the stack sam-node-dd-dev create events                                                              
2024-10-24 15:21:52,773 | Stack Event: {'StackId':                                                                                              
'arn:aws:cloudformation:us-west-2:053655145506:stack/sam-node-dd-dev/91591640-8b1a-11ef-962b-02438722d453', 'EventId':                          
'HelloWorldFunction-UPDATE_IN_PROGRESS-2024-10-24T22:21:40.567Z', 'StackName': 'sam-node-dd-dev', 'LogicalResourceId': 'HelloWorldFunction',    
'PhysicalResourceId': 'sam-node-dd-dev-HelloWorldFunction-nEpjJpxTth56', 'ResourceType': 'AWS::Lambda::Function', 'Timestamp':                  
datetime.datetime(2024, 10, 24, 22, 21, 40, 567000, tzinfo=tzutc()), 'ResourceStatus': 'UPDATE_IN_PROGRESS', 'ResourceProperties':              
'{"Role":"arn:aws:iam::053655145506:role/sam-node-dd-dev-HelloWorldFunctionRole-C8FCtCLCPm0d","Runtime":"nodejs20.x","Timeout":"3","LoggingConfi
g":{"LogFormat":"JSON"},"Handler":"/opt/nodejs/node_modules/datadog-lambda-js/handler.handler","Environment":{"Variables":{"DD_API_KEY_SECRET_AR
N":"arn:aws:secretsmanager:us-west-2:053655145506:secret:cela/datadog_api_key-oHab1s","DD_SITE":"datadoghq.com","DD_LAMBDA_HANDLER":"app.lambdaH
andler","DD_CAPTURE_LAMBDA_PAYLOAD":"false","DD_VERSION":"v1.2.3","DD_FLUSH_TO_LOG":"true","DD_SERVICE":"sam-node-dd","DD_TRACE_ENABLED":"true",
"DD_ENV":"dev","DD_SERVERLESS_LOGS_ENABLED":"true","DD_ENHANCED_METRICS":"true","DD_MERGE_XRAY_TRACES":"false"}},"Code":{"S3Bucket":"aws-sam-cli
-managed-default-samclisourcebucket-1fo2l63xfmwdy","S3Key":"sam-node-dd/88604a918d89fdebe227ba16b991f9a5"},"Layers":["arn:aws:lambda:us-west-2:4
64622532012:layer:Datadog-Node20-x:112","arn:aws:lambda:us-west-2:464622532012:layer:Datadog-Extension:58"],"Tags":[{"Value":"SAM","Key":"lambda
:createdBy"},{"Value":"v0.14.1","Key":"dd_sls_macro"},{"Value":"SAM","Key":"dd_sls_macro_by"}],"Architectures":["x86_64"]}'}                    
2024-10-24 15:21:52,776 | Skip previous event as time_stamp_marker: 2024-10-24 22:21:40.567000 is after the event time stamp: 2024-10-24        
22:21:40.567000+00:00                                                                                                                           
2024-10-24 15:21:52,778 | Exit from the describe event loop                                                                                     
2024-10-24 15:21:52,779 | Trial # 0 to get the stack sam-node-dd-dev create events                                                              
2024-10-24 15:21:58,123 | Stack Event: {'StackId':                                                                                              
'arn:aws:cloudformation:us-west-2:053655145506:stack/sam-node-dd-dev/91591640-8b1a-11ef-962b-02438722d453', 'EventId':                          
'HelloWorldFunction-UPDATE_IN_PROGRESS-2024-10-24T22:21:40.567Z', 'StackName': 'sam-node-dd-dev', 'LogicalResourceId': 'HelloWorldFunction',    
'PhysicalResourceId': 'sam-node-dd-dev-HelloWorldFunction-nEpjJpxTth56', 'ResourceType': 'AWS::Lambda::Function', 'Timestamp':                  
datetime.datetime(2024, 10, 24, 22, 21, 40, 567000, tzinfo=tzutc()), 'ResourceStatus': 'UPDATE_IN_PROGRESS', 'ResourceProperties':              
'{"Role":"arn:aws:iam::053655145506:role/sam-node-dd-dev-HelloWorldFunctionRole-C8FCtCLCPm0d","Runtime":"nodejs20.x","Timeout":"3","LoggingConfi
g":{"LogFormat":"JSON"},"Handler":"/opt/nodejs/node_modules/datadog-lambda-js/handler.handler","Environment":{"Variables":{"DD_API_KEY_SECRET_AR
N":"arn:aws:secretsmanager:us-west-2:053655145506:secret:cela/datadog_api_key-oHab1s","DD_SITE":"datadoghq.com","DD_LAMBDA_HANDLER":"app.lambdaH
andler","DD_CAPTURE_LAMBDA_PAYLOAD":"false","DD_VERSION":"v1.2.3","DD_FLUSH_TO_LOG":"true","DD_SERVICE":"sam-node-dd","DD_TRACE_ENABLED":"true",
"DD_ENV":"dev","DD_SERVERLESS_LOGS_ENABLED":"true","DD_ENHANCED_METRICS":"true","DD_MERGE_XRAY_TRACES":"false"}},"Code":{"S3Bucket":"aws-sam-cli
-managed-default-samclisourcebucket-1fo2l63xfmwdy","S3Key":"sam-node-dd/88604a918d89fdebe227ba16b991f9a5"},"Layers":["arn:aws:lambda:us-west-2:4
64622532012:layer:Datadog-Node20-x:112","arn:aws:lambda:us-west-2:464622532012:layer:Datadog-Extension:58"],"Tags":[{"Value":"SAM","Key":"lambda
:createdBy"},{"Value":"v0.14.1","Key":"dd_sls_macro"},{"Value":"SAM","Key":"dd_sls_macro_by"}],"Architectures":["x86_64"]}'}                    
2024-10-24 15:21:58,127 | Skip previous event as time_stamp_marker: 2024-10-24 22:21:40.567000 is after the event time stamp: 2024-10-24        
22:21:40.567000+00:00                                                                                                                           
2024-10-24 15:21:58,129 | Exit from the describe event loop                                                                                     
2024-10-24 15:21:58,130 | Trial # 0 to get the stack sam-node-dd-dev create events                                                              
2024-10-24 15:22:03,445 | Stack Event: {'StackId':                                                                                              
'arn:aws:cloudformation:us-west-2:053655145506:stack/sam-node-dd-dev/91591640-8b1a-11ef-962b-02438722d453', 'EventId':                          
'644bd9b0-9256-11ef-a7d1-06b7c4aac59d', 'StackName': 'sam-node-dd-dev', 'LogicalResourceId': 'sam-node-dd-dev', 'PhysicalResourceId':           
'arn:aws:cloudformation:us-west-2:053655145506:stack/sam-node-dd-dev/91591640-8b1a-11ef-962b-02438722d453', 'ResourceType':                     
'AWS::CloudFormation::Stack', 'Timestamp': datetime.datetime(2024, 10, 24, 22, 22, 1, 916000, tzinfo=tzutc()), 'ResourceStatus':                
'UPDATE_COMPLETE'}                                                                                                                              
2024-10-24 15:22:03,448 | Stack Event: {'StackId':                                                                                              
'arn:aws:cloudformation:us-west-2:053655145506:stack/sam-node-dd-dev/91591640-8b1a-11ef-962b-02438722d453', 'EventId':                          
'63ce4540-9256-11ef-989c-0a09a9589bf1', 'StackName': 'sam-node-dd-dev', 'LogicalResourceId': 'sam-node-dd-dev', 'PhysicalResourceId':           
'arn:aws:cloudformation:us-west-2:053655145506:stack/sam-node-dd-dev/91591640-8b1a-11ef-962b-02438722d453', 'ResourceType':                     
'AWS::CloudFormation::Stack', 'Timestamp': datetime.datetime(2024, 10, 24, 22, 22, 1, 98000, tzinfo=tzutc()), 'ResourceStatus':                 
'UPDATE_COMPLETE_CLEANUP_IN_PROGRESS'}                                                                                                          
2024-10-24 15:22:03,450 | Stack Event: {'StackId':                                                                                              
'arn:aws:cloudformation:us-west-2:053655145506:stack/sam-node-dd-dev/91591640-8b1a-11ef-962b-02438722d453', 'EventId':                          
'HelloWorldFunction-UPDATE_COMPLETE-2024-10-24T22:21:58.571Z', 'StackName': 'sam-node-dd-dev', 'LogicalResourceId': 'HelloWorldFunction',       
'PhysicalResourceId': 'sam-node-dd-dev-HelloWorldFunction-nEpjJpxTth56', 'ResourceType': 'AWS::Lambda::Function', 'Timestamp':                  
datetime.datetime(2024, 10, 24, 22, 21, 58, 571000, tzinfo=tzutc()), 'ResourceStatus': 'UPDATE_COMPLETE', 'ResourceProperties':                 
'{"Role":"arn:aws:iam::053655145506:role/sam-node-dd-dev-HelloWorldFunctionRole-C8FCtCLCPm0d","Runtime":"nodejs20.x","Timeout":"3","LoggingConfi
g":{"LogFormat":"JSON"},"Handler":"/opt/nodejs/node_modules/datadog-lambda-js/handler.handler","Environment":{"Variables":{"DD_API_KEY_SECRET_AR
N":"arn:aws:secretsmanager:us-west-2:053655145506:secret:cela/datadog_api_key-oHab1s","DD_SITE":"datadoghq.com","DD_LAMBDA_HANDLER":"app.lambdaH
andler","DD_CAPTURE_LAMBDA_PAYLOAD":"false","DD_VERSION":"v1.2.3","DD_FLUSH_TO_LOG":"true","DD_SERVICE":"sam-node-dd","DD_TRACE_ENABLED":"true",
"DD_ENV":"dev","DD_SERVERLESS_LOGS_ENABLED":"true","DD_ENHANCED_METRICS":"true","DD_MERGE_XRAY_TRACES":"false"}},"Code":{"S3Bucket":"aws-sam-cli
-managed-default-samclisourcebucket-1fo2l63xfmwdy","S3Key":"sam-node-dd/88604a918d89fdebe227ba16b991f9a5"},"Layers":["arn:aws:lambda:us-west-2:4
64622532012:layer:Datadog-Node20-x:112","arn:aws:lambda:us-west-2:464622532012:layer:Datadog-Extension:58"],"Tags":[{"Value":"SAM","Key":"lambda
:createdBy"},{"Value":"v0.14.1","Key":"dd_sls_macro"},{"Value":"SAM","Key":"dd_sls_macro_by"}],"Architectures":["x86_64"]}'}                    
2024-10-24 15:22:03,454 | Stack Event: {'StackId':                                                                                              
'arn:aws:cloudformation:us-west-2:053655145506:stack/sam-node-dd-dev/91591640-8b1a-11ef-962b-02438722d453', 'EventId':                          
'HelloWorldFunction-UPDATE_IN_PROGRESS-2024-10-24T22:21:40.567Z', 'StackName': 'sam-node-dd-dev', 'LogicalResourceId': 'HelloWorldFunction',    
'PhysicalResourceId': 'sam-node-dd-dev-HelloWorldFunction-nEpjJpxTth56', 'ResourceType': 'AWS::Lambda::Function', 'Timestamp':                  
datetime.datetime(2024, 10, 24, 22, 21, 40, 567000, tzinfo=tzutc()), 'ResourceStatus': 'UPDATE_IN_PROGRESS', 'ResourceProperties':              
'{"Role":"arn:aws:iam::053655145506:role/sam-node-dd-dev-HelloWorldFunctionRole-C8FCtCLCPm0d","Runtime":"nodejs20.x","Timeout":"3","LoggingConfi
g":{"LogFormat":"JSON"},"Handler":"/opt/nodejs/node_modules/datadog-lambda-js/handler.handler","Environment":{"Variables":{"DD_API_KEY_SECRET_AR
N":"arn:aws:secretsmanager:us-west-2:053655145506:secret:cela/datadog_api_key-oHab1s","DD_SITE":"datadoghq.com","DD_LAMBDA_HANDLER":"app.lambdaH
andler","DD_CAPTURE_LAMBDA_PAYLOAD":"false","DD_VERSION":"v1.2.3","DD_FLUSH_TO_LOG":"true","DD_SERVICE":"sam-node-dd","DD_TRACE_ENABLED":"true",
"DD_ENV":"dev","DD_SERVERLESS_LOGS_ENABLED":"true","DD_ENHANCED_METRICS":"true","DD_MERGE_XRAY_TRACES":"false"}},"Code":{"S3Bucket":"aws-sam-cli
-managed-default-samclisourcebucket-1fo2l63xfmwdy","S3Key":"sam-node-dd/88604a918d89fdebe227ba16b991f9a5"},"Layers":["arn:aws:lambda:us-west-2:4
64622532012:layer:Datadog-Node20-x:112","arn:aws:lambda:us-west-2:464622532012:layer:Datadog-Extension:58"],"Tags":[{"Value":"SAM","Key":"lambda
:createdBy"},{"Value":"v0.14.1","Key":"dd_sls_macro"},{"Value":"SAM","Key":"dd_sls_macro_by"}],"Architectures":["x86_64"]}'}                    
2024-10-24 15:22:03,458 | Skip previous event as time_stamp_marker: 2024-10-24 22:21:40.567000 is after the event time stamp: 2024-10-24        
22:21:40.567000+00:00                                                                                                                           
2024-10-24 15:22:03,460 | Exit from the describe event loop                                                                                     
UPDATE_COMPLETE                     AWS::Lambda::Function               HelloWorldFunction                  -                                 
UPDATE_COMPLETE_CLEANUP_IN_PROGRE   AWS::CloudFormation::Stack          sam-node-dd-dev                     -                                 
SS                                                                                                                                            
UPDATE_COMPLETE                     AWS::CloudFormation::Stack          sam-node-dd-dev                     -                                 
2024-10-24 15:22:03,461 | Stack sam-node-dd-dev is not in progress. Its status is UPDATE_COMPLETE, and event is {'StackId':                     
'arn:aws:cloudformation:us-west-2:053655145506:stack/sam-node-dd-dev/91591640-8b1a-11ef-962b-02438722d453', 'EventId':                          
'644bd9b0-9256-11ef-a7d1-06b7c4aac59d', 'StackName': 'sam-node-dd-dev', 'LogicalResourceId': 'sam-node-dd-dev', 'PhysicalResourceId':           
'arn:aws:cloudformation:us-west-2:053655145506:stack/sam-node-dd-dev/91591640-8b1a-11ef-962b-02438722d453', 'ResourceType':                     
'AWS::CloudFormation::Stack', 'Timestamp': datetime.datetime(2024, 10, 24, 22, 22, 1, 916000, tzinfo=tzutc()), 'ResourceStatus':                
'UPDATE_COMPLETE'}                                                                                                                              
---------------------------------------------------------------------------------------------------------------------------------------------

CloudFormation outputs from deployed stack
---------------------------------------------------------------------------------------------------------------------------------------------
Outputs                                                                                                                                     
---------------------------------------------------------------------------------------------------------------------------------------------
Key                 HelloWorldFunctionIamRole                                                                                               
Description         Implicit IAM Role created for Hello World function                                                                      
Value               arn:aws:iam::053655145506:role/sam-node-dd-dev-HelloWorldFunctionRole-C8FCtCLCPm0d                                      

Key                 HelloWorldApi                                                                                                           
Description         API Gateway endpoint URL for Prod stage for Hello World function                                                        
Value               https://mp67axafv3.execute-api.us-west-2.amazonaws.com/Prod/hello/                                                      

Key                 HelloWorldFunction                                                                                                      
Description         Hello World Lambda Function ARN                                                                                         
Value               arn:aws:lambda:us-west-2:053655145506:function:sam-node-dd-dev-HelloWorldFunction-nEpjJpxTth56                          
---------------------------------------------------------------------------------------------------------------------------------------------


Successfully created/updated stack - sam-node-dd-dev in us-west-2

2024-10-24 15:22:03,610 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics            
2024-10-24 15:22:03,754 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics            
2024-10-24 15:22:03,756 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': 'a597b675-9d87-4a1d-b9d8-67080588f245', 'installationId':
'625ce50a-07d6-4382-9c6f-f97acd2ade37', 'sessionId': '3b406e9d-2776-4a75-a152-92e107e26b87', 'executionEnvironment': 'CLI', 'ci': False,        
'pyversion': '3.8.20', 'samcliVersion': '1.126.0', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': 'us-west-2', 'commandName':
'sam deploy', 'metricSpecificAttributes': {'projectType': 'CFN', 'gitOrigin': None, 'projectName':                                              
'3fc502424c2ceb660b5d59089a2d7df9842ea3f671bbeaff2309cd9702787e43', 'initialCommit': None}, 'duration': 62873, 'exitReason': 'success',         
'exitCode': 0}}]}                                                                                                                               
2024-10-24 15:22:03,756 | Unable to find Click Context for getting session_id.                                                                  
2024-10-24 15:22:03,762 | Sending Telemetry: {'metrics': [{'events': {'requestId': 'e01c1afc-e85c-4376-b42a-f33aea137492', 'installationId':    
'625ce50a-07d6-4382-9c6f-f97acd2ade37', 'sessionId': '3b406e9d-2776-4a75-a152-92e107e26b87', 'executionEnvironment': 'CLI', 'ci': False,        
'pyversion': '3.8.20', 'samcliVersion': '1.126.0', 'commandName': 'sam deploy', 'metricSpecificAttributes': {'events': [{'event_name':          
'SamConfigFileExtension', 'event_value': '.toml', 'thread_id': 'ed5a5fe84c0c43df9f3eea5cac8b3850', 'time_stamp': '2024-10-24 22:21:00.668',     
'exception_name': None}, {'event_name': 'SamConfigFileExtension', 'event_value': '.toml', 'thread_id': 'baa88b83a45f462f985e7a9a1b67e11f',      
'time_stamp': '2024-10-24 22:21:00.726', 'exception_name': None}]}}}]}                                                                          
2024-10-24 15:22:04,405 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read   
timeout=0.1)                                                                                                                                    
2024-10-24 15:22:04,408 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read   
timeout=0.1)  
@tredfield tredfield added the stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. label Oct 24, 2024
@tredfield tredfield changed the title Bug: sam deploy using --template parameter does not package Bug: sam deploy using --template parameter does not package application properly Oct 24, 2024
@bevand10
Copy link

bevand10 commented Oct 29, 2024

I have the same issue, with this context:

If used thus:

sam build --template-file my-template.yaml

SAM adds the files from a layer's ContentUri directory - eg layers/my-layer.

Say that directory contains a Makefile which in turn contains a pip install -r requirements.txt -t $(ARTIFACTS_DIR)/python directive, while sam build shows the Makefile being used, the libs added are not in the zip sent to S3 for deploy.

HOWEVER, if the template is named template.yaml and no --template-file arg is specified, then everything works as intended - the pip installed files are correctly added to the deployed zip sent to s3 for deploy. I.e. the stack is fully operational (imports from the layer work) if the template name is default, but broken if anything else.

Note that in my experience, it's ONLY the layer construction phase that appears broken, all other aspects of the alt-template filename use case are ok and deployed successfully - other resources, policies, parameters, outputs etc etc.

@hnnasit
Copy link
Contributor

hnnasit commented Oct 31, 2024

Hi @tredfield, when sam deploy is run without any options, it looks for the template file in the .aws-sam folder (built using sam build). If you pass in --template to sam deploy, it's using the non built template file to deploy. Running sam build again might just be re-using the previous build. I'm trying to understand was there any change to the template file and if template.yml is a different file that the one used to build/deploy initially?

@hnnasit hnnasit added blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale. area/deploy sam deploy command and removed stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/deploy sam deploy command blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale.
Projects
None yet
Development

No branches or pull requests

4 participants
@bevand10 @tredfield @hnnasit and others