You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using an openapi definition for a SpecRestApi where the x-amazon-apigateway-integration points to a Lambda function Alias, you will recieve the error 'Error: Template does not have any APIs connected to Lambda functions' when trying to run 'sam local start-api'.
Steps to reproduce:
Here is a simple CDK stack which was used to re-produce this issue.
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import * as apigateway from 'aws-cdk-lib/aws-apigateway';
import * as path from 'path';
export class SpecRestApiStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
// Define the Lambda function with inline code
const helloWorldFunction = new lambda.Function(this, 'HelloWorldFunctionSpec', {
runtime: lambda.Runtime.NODEJS_18_X,
handler: 'index.handler',
code: lambda.Code.fromAsset(path.join(__dirname, 'lambda')),
});
// Create a Lambda alias
const alias = new lambda.Alias(this, 'HelloWorldAliasSpec', {
aliasName: 'prod',
version: helloWorldFunction.currentVersion,
});
// Define the API Gateway using SpecRestApi
const api = new apigateway.SpecRestApi(this, 'SpecRestApi', {
apiDefinition: apigateway.ApiDefinition.fromInline({
openapi: '3.0.1',
info: {
title: 'SpecRestApi',
version: '1.0'
},
paths: {
'/test': {
get: {
'x-amazon-apigateway-integration': {
uri: `arn:aws:apigateway:${cdk.Aws.REGION}:lambda:path/2015-03-31/functions/${alias.functionArn}/invocations`,
httpMethod: 'POST',
type: 'aws_proxy'
},
responses: {
200: {
description: '200 response',
content: {
'application/json': {
schema: {
type: 'string'
}
}
}
}
}
}
}
}
})
});
// Grant permissions for the API Gateway to invoke the Lambda alias
alias.grantInvoke(new cdk.aws_iam.ServicePrincipal('apigateway.amazonaws.com'));
}
}
Build this stack using cdk synth, and then use sam build with the resulting template.
Then run sam local start-api
Observed result:
sam local start-ap --debug
2025-01-12 10:21:56 Attaching import module proxy for analyzing dynamic imports
2025-01-12 10:21:56,618 | No config file found in this directory.
2025-01-12 10:21:56,620 | OSError occurred while reading TOML file: [Errno 2] No such file or directory: '/home/ranger/projects/sam-local/.aws-sam/build/samconfig.toml'
2025-01-12 10:21:56,620 | Config file location: /home/ranger/projects/sam-local/.aws-sam/build/samconfig.toml
2025-01-12 10:21:56,621 | Config file '/home/ranger/projects/sam-local/.aws-sam/build/samconfig.toml' does not exist
2025-01-12 10:21:56,632 | OSError occurred while reading TOML file: [Errno 2] No such file or directory: '/home/ranger/projects/sam-local/.aws-sam/build/samconfig.toml'
2025-01-12 10:21:56,633 | Using config file: samconfig.toml, config environment: default
2025-01-12 10:21:56,633 | Expand command line arguments to:
2025-01-12 10:21:56,634 | --template_file=/home/ranger/projects/sam-local/.aws-sam/build/template.yaml --host=127.0.0.1 --port=3000 --static_dir=public
--layer_cache_basedir=/home/ranger/.aws-sam/layers-pkg --container_host=localhost --container_host_interface=127.0.0.1
2025-01-12 10:21:56,655 | local start-api command is called
2025-01-12 10:21:58,719 | No current session found, using default AWS::AccountId
2025-01-12 10:21:58,730 | Collected default values for parameters: {'BootstrapVersion': '/cdk-bootstrap/hnb659fds/version'}
2025-01-12 10:21:58,743 | CDK Path for resource HelloWorldFunctionSpecServiceRoleF796918C is ['Spec', 'HelloWorldFunctionSpec', 'ServiceRole', 'Resource']
2025-01-12 10:21:58,744 | Sam customer defined id is more priority than other IDs. Customer defined id for resource HelloWorldFunctionSpec17441592 is HelloWorldFunctionSpec
2025-01-12 10:21:58,744 | CDK Path for resource HelloWorldFunctionSpecCurrentVersion972EE62B1134dc36c01a9834549bf5ef22ce6e36 is ['Spec', 'HelloWorldFunctionSpec',
'CurrentVersion', 'Resource']
2025-01-12 10:21:58,745 | CDK Path for resource HelloWorldAliasSpec31D71541 is ['Spec', 'HelloWorldAliasSpec', 'Resource']
2025-01-12 10:21:58,745 | CDK Path for resource HelloWorldAliasSpecInvokeFcyXBRX02EWa52GlFECQiCzDt0fdRUDi4mo4foC5aUCDF9A5D5 is ['Spec', 'HelloWorldAliasSpec',
'InvokeFcyXBRX02EWa52GlF+ECQiCzDt0fdRUDi4mo4foC5aU=']
2025-01-12 10:21:58,746 | CDK Path for resource SpecRestApiB69335EA is ['Spec', 'SpecRestApi', 'Resource']
2025-01-12 10:21:58,746 | CDK Path for resource SpecRestApiDeployment33C0029Ab4278f349fd9e00e29327dd3f4381ff0 is ['Spec', 'SpecRestApi', 'Deployment', 'Resource']
2025-01-12 10:21:58,746 | CDK Path for resource SpecRestApiDeploymentStageprod6BB55B6A is ['Spec', 'SpecRestApi', 'DeploymentStage.prod', 'Resource']
2025-01-12 10:21:58,747 | CDK Path for resource CDKMetadata is ['Spec', 'CDKMetadata', 'Default']
2025-01-12 10:21:58,748 | Unable to resolve property FunctionVersion: OrderedDict([('Fn::GetAtt',
['HelloWorldFunctionSpecCurrentVersion972EE62B1134dc36c01a9834549bf5ef22ce6e36', 'Version'])]). Leaving as is.
2025-01-12 10:21:58,748 | 0 stacks found in the template
2025-01-12 10:21:58,749 | Collected default values for parameters: {'BootstrapVersion': '/cdk-bootstrap/hnb659fds/version'}
2025-01-12 10:21:58,760 | CDK Path for resource HelloWorldFunctionSpecServiceRoleF796918C is ['Spec', 'HelloWorldFunctionSpec', 'ServiceRole', 'Resource']
2025-01-12 10:21:58,760 | Sam customer defined id is more priority than other IDs. Customer defined id for resource HelloWorldFunctionSpec17441592 is HelloWorldFunctionSpec
2025-01-12 10:21:58,761 | CDK Path for resource HelloWorldFunctionSpecCurrentVersion972EE62B1134dc36c01a9834549bf5ef22ce6e36 is ['Spec', 'HelloWorldFunctionSpec',
'CurrentVersion', 'Resource']
2025-01-12 10:21:58,761 | CDK Path for resource HelloWorldAliasSpec31D71541 is ['Spec', 'HelloWorldAliasSpec', 'Resource']
2025-01-12 10:21:58,762 | CDK Path for resource HelloWorldAliasSpecInvokeFcyXBRX02EWa52GlFECQiCzDt0fdRUDi4mo4foC5aUCDF9A5D5 is ['Spec', 'HelloWorldAliasSpec',
'InvokeFcyXBRX02EWa52GlF+ECQiCzDt0fdRUDi4mo4foC5aU=']
2025-01-12 10:21:58,762 | CDK Path for resource SpecRestApiB69335EA is ['Spec', 'SpecRestApi', 'Resource']
2025-01-12 10:21:58,762 | CDK Path for resource SpecRestApiDeployment33C0029Ab4278f349fd9e00e29327dd3f4381ff0 is ['Spec', 'SpecRestApi', 'Deployment', 'Resource']
2025-01-12 10:21:58,763 | CDK Path for resource SpecRestApiDeploymentStageprod6BB55B6A is ['Spec', 'SpecRestApi', 'DeploymentStage.prod', 'Resource']
2025-01-12 10:21:58,763 | CDK Path for resource CDKMetadata is ['Spec', 'CDKMetadata', 'Default']
2025-01-12 10:21:58,764 | Unable to resolve property FunctionVersion: OrderedDict([('Fn::GetAtt',
['HelloWorldFunctionSpecCurrentVersion972EE62B1134dc36c01a9834549bf5ef22ce6e36', 'Version'])]). Leaving as is.
2025-01-12 10:21:58,765 | 9 resources found in the stack
2025-01-12 10:21:58,765 | Found Lambda function with name='HelloWorldFunctionSpec17441592' and CodeUri='HelloWorldFunctionSpec17441592'
2025-01-12 10:21:58,765 | --base-dir is not presented, adjusting uri HelloWorldFunctionSpec17441592 relative to /home/ranger/projects/sam-local/.aws-sam/build/template.yaml
2025-01-12 10:21:58,767 | Detected Inline Swagger definition
2025-01-12 10:21:58,768 | Parsing Swagger document using 3.0 specification
2025-01-12 10:21:58,768 | Found '0' authorizers in resource 'SpecRestApiB69335EA'
2025-01-12 10:21:58,769 | Extracted Function ARN: HelloWorldAliasSpec31D71541
2025-01-12 10:21:58,769 | No Lambda function ARN defined for integration containing ARN HelloWorldAliasSpec31D71541
2025-01-12 10:21:58,769 | Lambda function integration not found in Swagger document at path='/test' method='get'
2025-01-12 10:21:58,770 | Found '0' APIs in resource 'SpecRestApiB69335EA'
2025-01-12 10:21:58,770 | 0 APIs found in the template
2025-01-12 10:21:58,772 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2025-01-12 10:21:58,776 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2025-01-12 10:21:58,777 | Unable to find Click Context for getting session_id.
Expected result:
I would expect that the sam cli start-api be able to find my Lambda function which is referrenced via an Alias.
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
Description:
When using an openapi definition for a SpecRestApi where the x-amazon-apigateway-integration points to a Lambda function Alias, you will recieve the error 'Error: Template does not have any APIs connected to Lambda functions' when trying to run 'sam local start-api'.
Steps to reproduce:
Here is a simple CDK stack which was used to re-produce this issue.
Build this stack using
cdk synth
, and then usesam build
with the resulting template.Then run
sam local start-api
Observed result:
Expected result:
I would expect that the sam cli start-api be able to find my Lambda function which is referrenced via an Alias.
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
The text was updated successfully, but these errors were encountered: