The code is on github.
- Set up codebuild to build your code once a commit is made to your repository. You can also use codebuild to run your tests. When building is complete, the code is stored in s3
- Create a codepipeline that will trigger automatically when you push a commit to your repository ( bitbucket, github, codecommit etc). The first stage will be your code source and the second stage will be codebuild.
- When you push a commit, the pipeline will run. The code will be built and stored in S3. You can set up an S3 lifecyle rule to delete old code artifacts. You can also set up a CloudWatch event rule that will inform you via SNS of the state of the pipeline execution ( successful or failed ).
- The code now needs to be pushed to cpanel. Set up an S3 event that monitors for new object creation. When code is pushed, set the event should invoke a lambda function.
- The Lambda will fetch the code from S3 and store it in its /tmp directory which is limited to 512 mb. The lambda will unzip the code and push it to cpanel using FTP. FTP credentials are fetched from the AWS Parameter Store. Lambda can then inform you via SNS when the code has been successfully pushed. Lambda has a maximum running time of 15 minutes.
codepipeline_cpanel_push_lambda.py
IAM Permissions Required
- cloudwatch
- S3
- SNS
- SSM
Lambda Environment Variables
- bucket: bucket name for bucket that stores codepipeline artifacts
- ftp_hostname
- sns_topic : arn of sns topic to send you a notification when code has been pushed to cpanel
- region
- ftp_directory: where files will be pushed to
- ftp_hostname: hostname of the cpanel server
The function named codepipeline_ssh_push_lambda.py
is for the case where code is pushed to a server via SSH, which offers increased security as the data between the lambda function and the server will be encrypted.
Lambda environment variables in this case.
target_host: IP address of the server.
zipped_src: path in /tmp directory of lamba temporary storage where the zipped code downloaded from S3 will be stored eg /tmp/zipped.
unzipped_src: path in /tmp directory of lamba temporary storage where the unzipped code will be stored e.g /tmp/unzipped.
Top comments (0)