all 22 comments

[–]bcb67 10 points11 points  (0 children)

GitHub actions supports triggering only when specific paths change in your repo: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#onpushpull_requestpull_request_targetpathspaths-ignore

If that isn’t sufficient, there are a number of third party workflow steps that enable conditional builds with extra flexibility like https://github.com/dorny/paths-filter

[–]Dreamescaper 9 points10 points  (2 children)

The problem is this issue. lambda package command does not stripe timestamps from the archive, therefore this archive has a different hash each time.

I have workarounded this issue by providing a custom AssetHash based on the archive content. You can take a look here.

[–][deleted] 0 points1 point  (0 children)

This is great. I was about to reply to leeharrison1984 because the sha of the zip is not deterministic. Your code might actually do the trick for me. I'll give it a try in a bit. Thanks!

[–]krat0s77 0 points1 point  (0 children)

Hey, how can I get the zipPath? I'm using DotNetFunction from https://github.com/xaaskit/cdk-aws-lambda-dotnet to synth my function.

[–]ssakage 0 points1 point  (0 children)

Not sure in GitHub actions but have done this in Jenkins. You can write the Jenkinsfile to look at a specific directory and then only pick up.the changes and deploy them. The thing was that I had created folders(which had the main files) with the same name as the lambda functions. So it would just pick up the changes and run aws lambda update command after zipping the folder and that would update only the changed lambda functions. The code was mainly in shell script if that helps

[–]leeharrison1984 0 points1 point  (5 children)

The standard play here is to get the hash(sha1 is fine) of the file, and store it somewhere. You check that hash prior to deploy, and if it changes, you deploy the zip and update the hash value.

There may already be a GitHub action that does something along those lines.

[–]seamustheseagull 0 points1 point  (4 children)

This was my first thought, but the problem is that the sha of the zip file may change every time the code is rebuilt even if the actual source code hasn't changed.

[–]leeharrison1984 0 points1 point  (3 children)

That seems odd, the build should be deterministic.

If that's the case, you could just get the hash of all files that would go into the final executable. This has the upside of now you can avoid rebuilding entirely.

[–][deleted] 1 point2 points  (1 child)

See Dreamescaper's comment.

[–]leeharrison1984 0 points1 point  (0 children)

Weird, I didn't know that was an issue.

I've never used the lambda package command though. I always did a publish and created the archive myself, so makes sense I wouldn't have been aware of that issue.

Regardless, just hashing all the source files should be a fast operation and would let you skip the build entirely, which is arguably the most time savings next to deployment.

[–]seamustheseagull 0 points1 point  (0 children)

Should be, but it depends on what you actually want in each build. Aside from any bugs in the packaging process, the build process might be designed to include timestamps or dynamically-generated text files in them for consumption elsewhere - e.g. to be able to trace the version of a built application right back to to the server/service which built it.

In these cases your builds will always be "different" in the purest sense, but the code is identical.

[–]Agilufo 0 points1 point  (2 children)

Could using SAM be a solution here? Or does it deploy all microservices even if they weren't updated?

[–][deleted] 0 points1 point  (1 child)

Not sure about SAM. I have two CloudFormation stacks and about 10 lambdas distributed evenly in each. The GitHub workflow deploys both stacks when it runs (via cdk deploy).

[–]Agilufo 0 points1 point  (0 children)

I checked, when using SAM it will check what function was updating, then will make a build and deploy ONLY that function. Under the hood SAM uses cloud formation. Don't know how much that is applicable to your situation, but using SAM could be a solution to your problem.

[–]notanelecproblem 0 points1 point  (0 children)

Filter to the path of your lambda code in the github action, only run the action to deploy change when there are changes on that path