Triggering AWS codepipeline/codebuild from a scheduled lambda and blocking commit trigger
Asked Answered
C

3

5

I have a codepipeline using AWS codebuild building an AMI I planning on running on a weekly schedule for a fresh server image.

  1. I want to run it as a scheduled task, I thought of using lambda scheduled tasks for that, but didn't see an option of running pipeline source from lambda (I thought of using the api from lambda for that, but I rather have a mode declarative solution using the existing tools) Does anyone know of a built in solution for that?

  2. I DON'T want it to run on code push, how can that be enabled?

Edit: clarification

Why codepipeline? Because the task is too long for lambda. And I don't want to spin an ec2 instance for that (Billed by the hour) or keep an almost not working instance. Any other AWS tools that can handle that?

Communistic answered 11/7, 2017 at 13:26 Comment(2)
If you don't want to run on code push, CodePipeline may not be ideal for you, as it revolves around the continuous integration (CI) model, which explicitly triggers on every push. Are you dependent on CodePipeline for other reasons? Some additional detail on your rollout process might be helpful.Hellfire
I added a clarification on why codepipeline cc: @HellfireCommunistic
T
3

You can use the CLI command disable-stage-transition (or the corresponding API call with an SDK)

You can disable Inbound transitions to your Source stage. That will force it to not watch for changes. Then you can create a Lambda function and set it to a schedule. In the Lambda function you can use the enable-stage-transition call to turn back on the source input.

If you don't care about changes in your repository at all, you never have to turn on the Inbound Source transition and simply call the start-pipeline-execution command.

Thermophone answered 14/7, 2017 at 15:52 Comment(3)
Looks like an interesting solution! I'll check it outCommunistic
Disabling stage transition, has strange side effects, but start-pipeline-execution is the way to go. Thanks!Communistic
@Communistic can you describe the strange side effects? I have only been playing around with some tests with itThermophone
S
5

AWS CodePipeline is now available as a CloudWatch events target. CloudWatch events supports scheduling, so you can use this to automatically start your pipeline on a schedule.

An option called PollForSourceChanges was also recently added on source actions which when set to false will not start your pipeline automatically via the existing polling mechanism.

It is intended to be used in conjunction with CloudWatch events for customers who want to start their pipeline exclusively from CloudWatch events.

It sounds like a combination of these two features would suit your use-case well.

Susysuter answered 28/8, 2017 at 23:21 Comment(0)
T
3

You can use the CLI command disable-stage-transition (or the corresponding API call with an SDK)

You can disable Inbound transitions to your Source stage. That will force it to not watch for changes. Then you can create a Lambda function and set it to a schedule. In the Lambda function you can use the enable-stage-transition call to turn back on the source input.

If you don't care about changes in your repository at all, you never have to turn on the Inbound Source transition and simply call the start-pipeline-execution command.

Thermophone answered 14/7, 2017 at 15:52 Comment(3)
Looks like an interesting solution! I'll check it outCommunistic
Disabling stage transition, has strange side effects, but start-pipeline-execution is the way to go. Thanks!Communistic
@Communistic can you describe the strange side effects? I have only been playing around with some tests with itThermophone
S
0

Currently, these are the Codepipeline detection options when using Codecommit enter image description here

Even though this configures the CloudWatch Events to automatically start when a change occurs, you can just log into the Cloudwatch console and disable or modify the event as you like.

Since the events can run on a schedule, you may not even need lambda

Smacking answered 15/2, 2021 at 13:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.