# Getting autogenerated function already exists error

**URL:** <https://forum.serverless.com/t/getting-autogenerated-function-already-exists-error/9269>\
**Category:** Serverless Framework\
**Tags:** aws, lambda, cloudformation\
**Created:** [September 10, 2019, 6:08am UTC](https://forum.serverless.com/t/getting-autogenerated-function-already-exists-error/9269 "2019-09-10T06:08:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![adimoraret](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/adimoraret/32/1552_2.png) [@adimoraret](https://forum.serverless.com/u/adimoraret)\
**Post date:** [September 10, 2019, 6:08am UTC](https://forum.serverless.com/t/getting-autogenerated-function-already-exists-error/9269/1 "2019-09-10T06:08:21Z")

</div>

I have a service with the following configuration and it looks like, according to the documentation, a hidden function gets created: **content-dev-custom-resource-existing-s3** with logical id: **CustomDashresourceDashexistingDashs3LambdaFunction**

So when I want to change the environment company variable from company1 to company2, even if the s3 buckets are completely different, I get the following error:

> An error occurred: CustomDashresourceDashexistingDashs3LambdaFunction - content-dev-custom-resource-existing-s3 already exists in stack arn:aws:cloudformation:us-west-2…

Is there any way I could change that autogenerated logical id (CustomDashresourceDashexistingDashs3LambdaFunction) to depend on some environment variables?

Here is some of my serverless.yml configuration

```
service: content
provider:
  name: aws
  stackName: content-${self:provider.stage}-${self:provider.environment.COMPANY}
  stage: dev
  environment:
    COMPANY: company1
functions:
  myFunction:
    handler: src/handler.myFunction
    name: ${self:provider.stage}-${self:provider.environment.COMPANY}-myFunction
    events:
     - s3:
         bucket: ${file(./env.${self:provider.stage}.${self:provider.environment.COMPANY}.json):BUCKET}
         event: s3:ObjectCreated:Put
         rules:
         - prefix: content/
         existing: true

```

---

<div class="post-metadata">

**Author:** ![anthcp](https://avatars.discourse-cdn.com/v4/letter/a/71c47a/32.png) [@anthcp](https://forum.serverless.com/u/anthcp)\
**Post date:** [October 25, 2019, 5:27am UTC](https://forum.serverless.com/t/getting-autogenerated-function-already-exists-error/9269/2 "2019-10-25T05:27:27Z")

</div>

I have a similar problem but its not an sls bug. In my case, its because AWS don’t allow 2 lambda’s to share the same S3 event…  
regards

Anthony
