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

Can the log retention period be changed based on dev, production environment? #11

Open
neeraj87 opened this issue Apr 16, 2022 · 1 comment

Comments

@neeraj87
Copy link

I want to modify the log retention period based on which env my lambda is deployed for. The below is my serverless.yml code.

functions:
  myAPI:
    name: ${self:service}-${self:custom.stage}-api
    handler: build/lambda.handler
    logRetentionInDays: 14
    events:
      - http:
          method: any
          path: /api/{proxy+}
          cors:
            origins:
              - "*"
            headers:
              - Content-Type
              - X-Amz-Date
              - Authorization
              - X-Api-Key
              - X-Amz-Security-Token
            allowCredentials: true
            maxAge: 86400

As you can see the lambda is deployed to different environment which is specified by ${self:custom.stage} - the stage var is coming from a buildspec file and can have two values dev or prod.

If the stage is dev then I want the retention period to be 14 days and if its prod then 60 days. Is there a way to achieve this?

@Adam21e
Copy link

Adam21e commented Jan 5, 2023

You could pass it as an environmental var.

Another way, is to have a per environment setting in the custom section of your serverless.yml:

custom:
  stages:
    prod:
      logDays: 60
    dev:
      logDays: 14

You can then reference it in your function. Or in the custom area if you want it applied globally.

functions:
  myAPI:
    handler: build/lambda.handler
    logRetentionInDays: ${self:custom.stages.${self:custom.stage}.logDays}

See the doco for more details: https://www.serverless.com/framework/docs/providers/aws/guide/variables#recursively-reference-properties

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants