can we do something like Terraform Plan in Serverless? - amazon-web-services

when I change something in my lambda repo and redeploy the lambda with serverless framework it make changes. I want to know the changes that going to happen prior to deploying the lambda.
I tried serverless changeset plugin, but it doesn't show a comparison between my current lambda configuration and the changes going to happen by deploying the lambda after making some changes in my lambda repo [e.g. the lambda name, tags etc.]

You can enable changesets with deploymentMethod: changesets so that serverless deploy doesn't actually execute the changes, but instead creates a changeset inside CloudFormation which you can inspect inside the console and then initiate from there.

Related

Serverless AWS container lambda (node) not being updated

So, first go at AWS LAmbda Containers (need to deploy a "big-ish" Lambda) and we use Serverless framework for all other Lambdas and I tried it for the container as well.
It all went fine and the Lambda was created with all the expected parameters following this blog/guide: https://www.serverless.com/blog/container-support-for-lambda
Of course I had messed up the code and forgotten a module so teh Lambda didn't run in AWS.
I added the module and did a re-deploy (sls deploy) from my laptop and it writes out everything as "success" like in half a second so it is clear it is not deploying anything (I am using the --force flag as well but no difference.
The only way to get it updated seems to be to alter some code and save it and Serverless will "detect" a change and redeploy (for real).
This will cause a problem in our DevOps deploy pipeline so any way of getting it redeploying through a parameter/command?

Pipeline replaces previously deployed lambda when deploying new lambda

I'm referencing this aws tutorial to deploy our lambdas cross-account wise.
I'm able to get the lambdas to deploy over successfully but I notice that if I go deploy another lambda (lambda_b), RE-USING the SAME pipeline but for a different lambda, this different lambda (lambda_b) will replace the other lambda (say lambda_a) that was deployed earlier so that at any time, I only have a single lambda within the aws console.
Could this replacement be happening because of how i'm creating the changeset?
I just don't know how to proceed or where to look to get an idea of why it doesn't deploy lambda_b without replacing lambda_a even though we're re-using the same pipeline for all lambdas.
To deploy lambda_a I had to go through all steps, 1-6 of the tutorial linked above
However, to deploy lambda_b, I only rerun step 4 and 5 of the above, is that maybe why? When I try rerunning from the beginning again, it doesn't see the changeset for step 1
In the codepipiline, cloudformation yaml file, is there a way to set a retain:true attribute or some kind of way so that I can show all the lambdas that we've deployed so far; right now, i'm only able to show the lambda that was lastly deployed since a new lambda deployment (lambda_b) always replaces the old lambda deployment (lambda_a)
I want the console to show both lambda_a, and lambda_b
Seeing as you're using CloudFormation to deploy the lambda function, when a resource (lambda_a) is removed from the template it will be deleted as part of the CloudFormation clean up step.
You need to retain both functions in the template you're deploying to have both lambda_a and lambda_b deployed at the same time.

Re-deploy AWS CloudWatch Logs with serverless framework

I deployed an AWS service using the serverless framework, which created and deployed all the resources automatically.
But later on I accidentally deleted the log group for this service, and no logs are beeing created anymore.
Is there a way to recreate / redeploy just the log-group resource, because serverless --remove & serverless --deploy would delete all existing resources and create new ones which would be bad in my case.
Any ideas?
Comment out the function in serverless.yml, deploy, uncomment the function and deploy again. As far as I can tell, serverless tries to remove the log group when you "remove" the function and then create it when you "add" the function.
Also, afaict, you have to actually deploy. You can't just save, you have to do the full stack update for serverless to notice.
sls deploy -f <function name>
Or you can manually just create the log groups for now

A way to automate cloudformation templates deployment

Is there any way to automate cloudformation templates deployment? I mean it would be awesome if I just push the changes in the code and somebody looking for those changes in the code and once they appear - deploy the updated template.
Yes, with AWS Code Pipeline !
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/continuous-delivery-codepipeline.html
With AWS CloudFormation and AWS CodePipeline, you can use continuous delivery to automatically build and test changes to your AWS CloudFormation templates [...]
AWS CodePipeline has built-in integration with AWS CloudFormation, so you can specify AWS CloudFormation-specific actions, such as creating, updating, or deleting a stack, within a pipeline.
CodePipeline is a great way to do what you're looking for.
At Giftbit we do this is by having a Github Repo that has our CloudFormation template in it.
When we want to make a change, we make the changes on a branch in the repo, and create a pull request into the staging branch. CodePipeline monitors the staging branch then automates a CodeBuild to validate the templates, package any SubStacks, then creates a Change Set and Executes it.
Below are have some examples to help Quick Start anyone interested:
Continuous Integration CloudFormation Template Example
Serverless Application Model (SAM) that gets deployed

AWS CloudFormation does not recreate my application

I follow the tutorial on http://docs.aws.amazon.com/lambda/latest/dg/automating-deployment.html
The tutorial demonstrate how to automatically deploy a lambda and an API gateway using AWS cloudformation.
After some time I was able to complete the tutorial with success. This means that when I push a commit to the github repository linked to the AWS CodePipeline the changed code is uploaded/packaged to AWS -> build -> and deployed (i.e. i can see the code change)
My problem is that I tried to delete the lambda function and then invoke the Codepipeline by pushing a git commit. This trickered the codepipeline and I could watch source, build and staging steps complete successfully. However, I cannot find the lambda? I thought that cloudformation would recreate the application ? Can you help?
If you deleted the function manually then you're most likely running into this issue:
Resources that are created as part of an AWS CloudFormation stack must be managed from the same stack. Modifications to a resource must be done by a stack update. If a resource is deleted, a stack update is also necessary to remove the resource from the template. If a resource has been accidentally or purposely manually deleted, you can encounter errors when attempting to perform a stack update.
https://aws.amazon.com/premiumsupport/knowledge-center/failing-stack-updates-deleted/
You can resolve this by manually recreating the resource with the same name, then allowing CloudFormation to manage the resource in future.
The reason why I did not see any lambda function was because I only created the change set ("create or update change set") and missed to add the actual deploy stage "execute change set".