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

Triggers duplicated on each deploy #66

Closed
jeanblanchard opened this issue Jun 21, 2017 · 7 comments
Closed

Triggers duplicated on each deploy #66

jeanblanchard opened this issue Jun 21, 2017 · 7 comments

Comments

@jeanblanchard
Copy link
Contributor

Using version 2.2.1 or 2.2.0

My lambda is configured with a "CloudWatch Events - Schedule" trigger.
Each time I run mvn lambda:deploy-lambda, a new trigger is added to the lambda, pointing to the same event.

Configuration details (extract):

      <plugin>
        <groupId>com.github.seanroy</groupId>
        <artifactId>lambda-maven-plugin</artifactId>
        <version>${lambda-maven-plugin.version}</version>
        <configuration>
          <functionCode>${project.build.directory}/${project.build.finalName}.jar</functionCode>
          <version>dev</version>
          <s3Bucket>${s3-bucket}</s3Bucket>
          <lambdaRoleArn>${lambda-role}</lambdaRoleArn>
          <region>eu-west-1</region>
          <runtime>java8</runtime>
          <timeout>60</timeout>
          <memorySize>256</memorySize>
          <lambdaFunctionsJSON>
            [
              {
                "functionName": "EC2Backup",
                "handler": "com.example.EC2Backup",
                "triggers": [
                  {
                    "integration": "CloudWatch Events - Schedule",
                    "ruleName": "daily-weekday-5am",
                    "ruleDescription": "5am on weekdays",
                    "scheduleExpression": "cron(0 5 ? * MON-FRI *)"
                  }
                ]
              }
            ]
          </lambdaFunctionsJSON>
        </configuration>
      </plugin>

Maven logs

$  mvn lambda:deploy-lambda
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building backups 4.0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- lambda-maven-plugin:2.2.1:deploy-lambda (default-cli) @ backups ---
[INFO] backups-4.0.0.jar exists in S3 with MD5 hash 000000000000000000
[INFO] backups-4.0.0.jar is up to date in AWS S3 bucket example. Not uploading...
[INFO] ---- Create or update EC2Backup -----
[INFO] Cleaning up orphaned triggers.
[INFO] About to update functionCode for EC2Backup
[INFO] About to update functionConfig for EC2Backup
[INFO] Alias dev updated for EC2Backup with version 1
[INFO] About to create or update CloudWatch Events - Schedule trigger for daily-weekday-5am
[INFO] Created CloudWatch Events - Schedule trigger arn:aws:events:eu-west-1:0000000000:rule/daily-weekday-5am
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.282 s
[INFO] Finished at: 2017-06-21T12:53:40+02:00
[INFO] Final Memory: 17M/123M
[INFO] ------------------------------------------------------------------------
@SeanRoy
Copy link
Owner

SeanRoy commented Jun 22, 2017

Interesting, I can't reproduce this without setting -DforceUpdate=true. The log output (Created CloudWatch Events...) is misleading, it's not creating a new one, just updating the existing one. You only have one CloudWatch event rule pointed at your lambda function.

@jeanblanchard
Copy link
Contributor Author

Turns out, only the info on the lambda trigger tab is wrong. The lambda is indeed triggered only once per event. The info is correct on the CloudWatch rule page, and with the CLI aws events commands.

So it's possibly just a display issue on the AWS side.

That said, maybe the issue could be mitigated by checking on deploy whether the event has changed, and skip the update if it is unchanged?

@SeanRoy
Copy link
Owner

SeanRoy commented Jun 23, 2017

The code does actually check to see if the event has been changed. It compares the event rule name, the schedule expression and the description. If any of these have been changed, it updates the event rule.
I just ran a test of this functionality in 2.2.1 and the event was only updated after I changed one or more of those three things.

@SeanRoy
Copy link
Owner

SeanRoy commented Jun 26, 2017

@jeanblanchard Can I close this issue?

@jeanblanchard
Copy link
Contributor Author

jeanblanchard commented Jun 28, 2017

After further investigating, it appears that, in createOrUpdateScheduledRule, isKeepAliveChanged() always returns true if there is no keepAlive defined. This forces an update of the rule.

After updating the rule itself, a new permission is added for the rule (the permissions are not cleaned up, that I could see). This is what is causing the duplicated "events" that I see in the triggers tab. I could confirm this by manually removing the duplicated permissions using the CLI.

PS: I would create a PR for this, now that I have the project sitting in my IDE, but I don't really understand how the keepAlive works (or what the keepalive check is doing at all in the schedule rule check), so I wouldn't want to break everything...

@SeanRoy
Copy link
Owner

SeanRoy commented Jun 28, 2017

OK thanks for your investigation, I'll remove the keep alives from my configuration and retest.

SeanRoy pushed a commit that referenced this issue Jun 28, 2017
@SeanRoy
Copy link
Owner

SeanRoy commented Jun 29, 2017

Resolved in 2.2.2

@SeanRoy SeanRoy closed this as completed Jun 29, 2017
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