GithubHelp home page GithubHelp logo

Comments (4)

joshverma avatar joshverma commented on June 22, 2024

Have you found a solution for this?

from serverless.

locerito avatar locerito commented on June 22, 2024

Any solutions or workaround?

from serverless.

charlotteveitner avatar charlotteveitner commented on June 22, 2024

Any solutions or workaround?

@locerito I ended up splitting the events and deploying two seperate lambda functions with half of the events in each. Obviously not the cleanest approach but at least I am still able to deploy 👍🏽

from serverless.

locerito avatar locerito commented on June 22, 2024

Any solutions or workaround?

@locerito I ended up splitting the events and deploying two seperate lambda functions with half of the events in each. Obviously not the cleanest approach but at least I am still able to deploy 👍🏽

@charlotteveitner, Thanks for the answer, I will investigate a little more but since there is no clean way to do it, for now I apply another approach.
I'll tell you what I've done in case you're interested.

I apply a common permission to all event bridge rules with a wildcard.

resources:
  Resources:
    PermissionToCallEventRouterController:
      Type: "AWS::Lambda::Permission"
      Properties: 
        Action: lambda:InvokeFunction
        FunctionName: 
          Ref: EventUnderscorerouterUnderscorecontrollerLambdaFunction
        Principal: "events.amazonaws.com"
        SourceArn: "arn:aws:events:${self:provider.region}:${file(config.${opt:stage, 'dev'}.json):account}:rule/ocr_*"

To deploy, I run a package command, then I delete all EventBridgeLambdaPermission cloudformation resources for every rule in the cloudformation template files, and finally deploy with the package parameter.

serverless package --stage $ENVIRONMENT
python remove_cloudformation_resources.py .serverless/serverless-state.json EventUnderscorerouterUnderscorecontrollerEventBridgeLambdaPermission
python remove_cloudformation_resources.py .serverless/cloudformation-template-update-stack.json EventUnderscorerouterUnderscorecontrollerEventBridgeLambdaPermission
serverless deploy --stage $ENVIRONMENT --package .serverless

This is the python code I used (remove_cloudformation_resources.py):

import json
import sys


def read_json_file(file):
    with open(file) as json_file:
        data = json.load(json_file)
    return data


def write_json_file(file, data):
    with open(file, 'w') as outfile:
        json.dump(data, outfile, indent=2)


def remove_resources_from_serverless_state(data, name):
    data_copy = data.copy()
    cloudformation_template = data["service"]["provider"]["compiledCloudFormationTemplate"]["Resources"]
    cloudformation_template_copy = cloudformation_template.copy()
    for resource_name, item in cloudformation_template.items():
        if item["Type"] == "AWS::Lambda::Permission" and resource_name.startswith(name):
            print("Removing resource: " + resource_name)
            cloudformation_template_copy.pop(resource_name, None)
    data_copy["service"]["provider"]["compiledCloudFormationTemplate"]["Resources"] = cloudformation_template_copy
    return data_copy

def remove_resources_from_cloudformation(data, name):
    data_copy = data.copy()
    cloudformation_template = data["Resources"]
    cloudformation_template_copy = cloudformation_template.copy()
    for resource_name, item in cloudformation_template.items():
        if item["Type"] == "AWS::Lambda::Permission" and resource_name.startswith(name):
            print("Removing resource: " + resource_name)
            cloudformation_template_copy.pop(resource_name, None)
    data_copy["Resources"] = cloudformation_template_copy
    return data_copy


if __name__ == "__main__":
    filename = sys.argv[1]
    resource_pattern = sys.argv[2]

    data = read_json_file(filename)
    if "serverless-state" in filename:
        data_fix = remove_resources_from_serverless_state(data, resource_pattern)
    elif "cloudformation-template" in filename:
        data_fix = remove_resources_from_cloudformation(data, resource_pattern)
    write_json_file(filename, data_fix)

from serverless.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.