How to use TerraForm to create pipeline that deploys lambda function - amazon-web-services

I am trying to create a pipeline using terraform to create a codepipeline in aws to automatically deploy a lambda function.
i have already created 2 stages to get the code from github and build the artifact using codebuild and store the artifact to S3.
But i can't seem to find a terraform configuration for the codedeploy to deploy the artifact from s3 to lambda. I do see there is deployment setting from the console where i can specify the detail of the deployment.

Related

is it possible deploy azure infrastructure with terraform using AWS codecommit and AWS code pipeline?

i want to deploy Azure Infrastructure with leverage of AWS codecommit and AWS codepipeline is it possible?
AWS Codecommit to mantain file in a Repo and Codepipeline to Deploy Infra
unfortunately I have not yet had the opportunity to try

Add a secondary source to AWS pipeline that use AWS SAM

I am very new to AWS's codebuild, pipelien and SAM. I know that I can set up codebuild to bring in two git repositories similar to this example. I was wondering if there is a way that I can update a SAM project's Codepipeline to use a secondary git source?

SAM/Serverless/CodeBuild clarification

I am hoping for some clarification around some terms I have been seeing on the web as it pertains to AWS and specifically lambdas. For starters, I would like the know how the commands sam build/deploy work versus setting up a CodeBuild job. Do I need a CodeBuild job to run those commands? What files specifically does the sam deploy command look for? Does it look for serverless.yml or template.yml or both? What is a sam.yml file or are they antiquated?
I have an app with a CodeBuild pipeline for a lambda, but I am expanding my repo to contain multiple lambdas and thinking about putting a serverless.yml file in each lambda directory, but I don't want to create a CodeBuild job and buildspec for each one. I assume sam deploy searches for all template.yml and serverless.yml files and constructs your stack as a whole (and updates only what needs to be updated?)
App is in Node if curious using API Gateway. Any insight would be appreciated.
I will try to give brief answers:
What does sam deploy do: It will zip the code and create cloudformation yaml file into .aws-sam folder and run cloudformation deploy.
Do we need CodeBuild to run same deploy: We still need some server to run sam deploy or build with node installed, which could be a local machine or remote server or a CodeBuild environment.
Do we need multiple templates? All Lambdas can be created in single template. But there is limit of 150 resources in cloudformation. if we have too many functions and APIs in single template, we will easily hit that limit. Each api might get converted into multiple cloud-formation resources. ex: 1 lambda function can be iam roles, cloudwatch logs, api routes, methods, integration, event source, etc.
Does sam deploy always looks for template.yaml By default yes, but can be easily overridden by passing --template-file sam deploy --template-file template-x.yml
Only changed resources are updated? Cloudformation update-stack updates only the resources that are changed.

AWS CodePipeline, CodeDeploy, SAM and Lambda: how to (inter)connect those?

I'm a kind of lost in the documentation.
I want to push Python code to a repo and use CodePipeline to deploy Lambdas.
I have CodeCommit repo, CodePipeline - so far this works and I can create/update CF stack to create supplementary resources.
I know AWS SAM can be used to deploy the functions using CF tpl, but how can I connect SAM with CodePipeline/CodeDeploy? The code should be taken from a 'source' pipeline action then deployed as lambda function.
If SAM isn't the best automated solution here then what should I use instead? Pipeline is the key requirement so we don't have to run something like aws cf update-stack manually, just push the code.
CodePipeline doesn't support deploying Lambda through CodeDeploy, so the approach is to use a CodeBuild Build action to generate an change set from the SAM template and feed it into a CloudFormation Deploy action. You can find a detailed instruction in the following doc.
https://docs.aws.amazon.com/lambda/latest/dg/build-pipeline.html
If you use SAM to deploy Lambdas, CodeDeploy is automatically used. For reference:
Gradual Code Deployment
Safe Lambda deployments

Cloudformation script for AWS Codepipeline code commit, Code Build and Code Deploy

I am new to write cloudformation script so I am seeking help for writing a CF script for provisioning AWS CICD setup using codepipeline, code commit, code build and code deploy.
Any help will be appreciated
Here is two pre-build CloudFormation Script you can refer.
Unit test environment using CloudFormation: Continuous Delivery of Nested AWS CloudFormation Stacks Using AWS CodePipeline | Github
AWS CI/CD Pipeline using CloudFromation | Github
Note: You can use CloudFormer to build your CF script