Reputation: 21
I’m using the Serverless Framework (sls
) to deploy an AWS Lambda function. When I run:
sls deploy --stage dev
I get this error:
✖ Error: Please specify a stack name using the --stack option, or persist it in the samconfig.toml file.
Context:
serverless.yml
already includes the service
field:
service: py-events
provider:
name: aws
template.yaml
file.Debug Logs:
The error traces to getCfnConfig
in the Serverless Framework, with the MISSING_STACK_NAME
code.
Question:
How do I resolve this stack name error, and why did it suddenly appear despite having a service
defined?
What I’ve tried:
stage: dev
to provider
in serverless.yml
.--stack my-stack-dev
in the CLI.Upvotes: 0
Views: 28
Reputation: 21
This error occurs when the Serverless Framework (or an integrated tool like AWS SAM) cannot resolve a CloudFormation stack name. Here’s how to fix it:
service
and stage
Are Properly ConfiguredAdd stage
under the provider
in serverless.yml
. The stack name is auto-generated as ${service}-${stage}
:
service: py-events
provider:
name: aws
stage: dev # 👈 Required for stack name resolution
region: us-east-1 # Optional but recommended
Override the default stack name in serverless.yml
:
provider:
name: aws
stackName: py-events-${sls:stage} # e.g., "py-events-dev"
If you’re not using AWS SAM:
template.yaml
(SAM’s config file).samconfig.toml
(if present).The Serverless Framework will then use its own stack naming logic.
If you are using SAM (e.g., for other resources):
samconfig.toml
in your project root:
version = 0.1
[default.deploy.parameters]
stack_name = "py-events-dev"
region = "us-east-1"
sls
:
sam deploy --config-file samconfig.toml
template.yaml
or samconfig.toml
file was added recently, the Serverless Framework may default to SAM’s deployment logic, which requires explicit stack names.serverless.yml
has service
, stage
, and region
:
service: py-events
provider:
name: aws
stage: dev
region: us-east-1
template.yaml
, samconfig.toml
).sls deploy --stage dev
This resolves the stack name ambiguity by forcing the Serverless Framework to use its internal naming convention.
After applying the solution, check the AWS CloudFormation console for a stack.
References:
Upvotes: 0