This is a template for Serverless backup of all repositories from Organization/User to AWS Code Commit - Below is a brief explanation of what I have generated for you:
.
├── README.md <-- This instructions file
├── backup <-- Source code for a lambda function
│ ├── app.py <-- Lambda function code
│ ├── requirements.txt <-- Lambda function code
├── template.yaml <-- SAM Template
└── tests <-- Unit tests
└── unit
├── __init__.py
└── test_handler.py
-
Add GitHub Token to SSM Parameter store with name
/GitHub/Token/< Github Username or Organization Name> Example: /GitHub/Token/pramodh-ayyappan
-
AWS CLI already configured with Administrator permission
-
pip3 install aws-sam-cli
SAM CLI is used to emulate Lambda uses our template.yaml
to understand how to bootstrap this environment (runtime, where the source code is, etc.) - The Lambda Function will get triggered automatically on a daily basis:
...
...
Events:
Serverless:
Properties:
Method: post
Path: /github
RestApiId:
Ref: ServerlessAPI
Type: Api
AWS Lambda Python runtime requires a flat folder with all dependencies including the application. SAM will use CodeUri
property to know where to look up for both application and dependencies:
...
ServerlessFunction:
Properties:
CodeUri: backup/
...
- Login into AWS Account
- Go to this link and select a specific region and deploy.
- Now copy generated AWS CLI Lambda Layer ARN and paste it in this file template.yaml at line 59.
- For git binary we are going to use already existing layer
arn:aws:lambda:us-east-1:553035198032:layer:git:10
AWS Lambda requires a flat folder with the application as well as its dependencies in deployment package. When you make changes to your source code or dependency manifest.
sam build
aws s3 mb s3://BUCKET_NAME
sam package \
--output-template-file packaged.yaml \
--s3-bucket REPLACE_THIS_WITH_YOUR_S3_BUCKET_NAME
sam deploy \
--template-file packaged.yaml \
--stack-name Serverless \
--capabilities CAPABILITY_IAM \
--parameter-overrides NotificationEmail="<your email>" GitOrgOrUser="< Github User or Organisation>" GitTokenSSMParameterKey="<ssm parameter key for git access token>" VpcId="<vpc id>" VpcSubnetIds="<subnet id>"
aws cloudformation describe-stacks \
--stack-name Serverless-Pramodh \
--query 'Stacks[].Outputs[?OutputKey==`ServerlessApi`]' \
--output table