dzimine / greengo

Simple YAML-based deployment framework for AWS Greengrass.
http://greengo.io
MIT License
70 stars 20 forks source link

Existing Lambdas #21

Open hounded opened 5 years ago

hounded commented 5 years ago

Hi Dmitri, Loving you work and will be using greengo in our production devices. What do you feel about using existing lambdas, as I deploy and manage all my lambdas with serverless, being able to use existing lambdas would be helpful something like;

ExistingLambdas:
  - name: d1Site
    aliasarn: arn:aws:lambda:<your lambda arn>
    greengrassConfig:
      MemorySize: 128000 # Kb, ask AWS why
      Timeout: 10 # Sec
      Pinned: True # Set True for long-lived functions
      Environment:
        AccessSysfs: False
        # ResourceAccessPolicies:
          # - ResourceId: 1_path_to_input
          #   Permission: 'rw'
        Variables:
           name: value
    def create_fn_defn(self):
        for l in self.group['ExistingLambdas']:
            functions = []
            functions.append({
                'Id': l['name'],
                'FunctionArn': l['aliasarn'],
                'FunctionConfiguration': l['greengrassConfig']
            })
            fd = self._gg.create_function_definition(
                Name=l['name'],
                InitialVersion={'Functions': functions}
            )
            self.state['FunctionDefinition'] = rinse(fd)
            _update_state(self.state)

            fd_ver = self._gg.get_function_definition_version(
                FunctionDefinitionId=self.state['FunctionDefinition']['Id'],
                FunctionDefinitionVersionId=self.state['FunctionDefinition']['LatestVersion'])

            self.state['FunctionDefinition']['LatestVersionDetails'] = rinse(fd_ver)
            _update_state(self.state)

This way I could run greengo create_fn_defn and I could deploy my existing lambda

dzimine commented 5 years ago

Thanks @hounded for the input: I have recently arrived to the same idea: we need support for Lambda that already exist. I'm split mind of how exactly:

Option 1: follow the AWS model and separate Lambdas from Lambda definitions. So that greengo.yaml will have two separate sections: Lambdas, where lambda functions defined in AWS Lambda, and LambdaDefinitions, which refer to both Lambdas defined inside greengo, and outside, by name. This is ideologically similar to your proposal just semantically different.

Option 2: keep Lambdas in one section for simplicity (don't expose AWS dirty underwear) but offer to refer existing Lambda by ARN... and may be by name? The absense of handler will indicate that the function is existing.

Lambdas:
  - name: NewLambda
    handler: function.handler
    package: lambdas/NewLambda
    alias: dev
    # role: 'arn:aws:iam::000000000000:role/base_lambda_role' # Use an existing role instead of auto-created one
    environment:
      foo: bar
    greengrassConfig:
      MemorySize: 128000 # Kb, ask AWS why
      Timeout: 10 # Sec
      Pinned: True # Set True for long-lived functions
      # the rest of AWS IoT function definition goes here

  -  name: my_existing_lambda  # refer already created Lambda by a name
    alias: dev
    environment:
      foo: bar
    greengrassConfig:
      MemorySize: 128000 # Kb, ask AWS why
      Timeout: 10 # Sec
      Pinned: True # Set True for long-lived functions
      # the rest of AWS IoT function definition goes here

I am leaning towards option 2. Appreciate your input.

PS. I am just back on refactoring greengo to v2 and want to incorporate ^ ^ into it. PPS. Help appreciated :)

hounded commented 5 years ago

Hi Dimitri right in the thick of it with deployment of hardware at the moment. So are you going with option 2 ? My coding level isn't probably on par with yours but am happy to make some pull requests. Cheers

dzimine commented 4 years ago

Note that this is not added by @QuinnCiccoretti and available in v1; will also be available in v2 when eventually merged.