I’m a bit new to serverless framework, so I’m a little confused on how to use multiple environments. Below, I’ve attached my serverless.yml file. This is a simple node app that calls out to hubspot for what will later be an emailer. It sets up a cron job that runs the lambda function every minute. When I deploy this to the prod stage, everything works just fine. However, if I change the serverless.yml stage to be something else than prod, then go to run serverless deploy I get the following error.
Error:
CREATE_FAILED: HubspotEmailAlertsLogGroup (AWS::Logs::LogGroup)
/aws/lambda/HubspotEmailAlerts already exists in stack arn:aws:cloudformation:us-east-1:635450555010:stack/HubspotEmailAlerts-prod/8ab5a175-ff74-12ec-a0cf-0aa4a8e30fd1
I’ve tried deleting the service, and the entire app, then recreating with the same results. Also I’ve tried deleting the CloudWatch stack. I’ve tried deleting everything and starting from a brand new app with a completely different name to have the same results. Whatever stage I deploy to first will work. If I try to run serverless deploy on another stage after that, it will inevitably return the same error as you can see above.
Is there something I’m doing wrong with setting up the serverless.yml file to run different environments?
org: testorg
app: email-alerts
service: HubspotEmailAlerts
configValidationMode: error
provider:
name: aws
region: "us-east-1"
runtime: nodejs14.x
stage: dev
memorySize: 128
timeout: 900
environment:
HUBSPOT_API_KEY: ${self:custom.hsSecret.apiKey}
iam:
role:
statements:
- Effect: Allow
Action:
- "secretsmanager:*"
Resource: '*'
package:
excludeDevDependencies: false
functions:
HubspotEmailAlerts:
name: HubspotEmailAlerts
handler: src/index.handler
events:
- schedule:
rate: rate(2 minutes)
enabled: true
custom:
hsSecret: ${ssm:/aws/reference/secretsmanager/${self:provider.stage}/hubspot}