North-Seattle-College / ad440-winter2021-thursday-repo

NSC AD 440 Winter 2021 Thursday cohort practicum repo
Apache License 2.0
2 stars 27 forks source link

Issue#240 create lambda cloud formation template #283

Open ahmadafrasiyab opened 3 years ago

ahmadafrasiyab commented 3 years ago

This pull request is for automating lambda deployment using AWS cloud formation and boto3.

Note The PR is not ready for merge as there are authorization issues on AWS while deployment.

ahmadafrasiyab commented 3 years ago

Pre-requisites

  1. You will need to install boto3 and python(if you don't have it already)
  2. Please use $ python -m pip install boto3 to install boto3
  3. AWS access key and secret are required. Currently there are authorization issues during deployment using both personal and gha access keys and secrets
  4. The template.json inside the lambda cloudFormation folder is for reference. The actual template(which is the same one as template.json) is being served from an S3 bucket as boto3 command required a valid URL for the template. I was not able to figure out how to give it a template file locally.
  5. The function code can be added inline as in this PR or it can be zipped and pulled from a separate S3 bucket.

Instructions

  1. Please pull the code in your local machine. Change your directory to Automation/lambda cloudFormation.
  2. Use the following command: python lambdaCloudFormationDeploy.py AWS_ACCESS_KEY AWS_SECRET THE_NAME_OF_YOUR_STACK
  3. If the deployment goes well, you should see the following message:
    
    Response Data:  {'StackId': 'arn:aws:cloudformation:us-west-2:061431082068:stack/afrasiyabtest1/acd11d50-87b8-11eb-9078-0296b3ac8a31', 'ResponseMetadata': {'RequestId': '3490b863-ad1ponseMetadata': {'RequestId': '3490b863-ad11-4610-9e14-869f72de07a5', 
    'HTTPStatusCode': 200, 'HTTPHeaders': {'x-amzn-requestid': '3490b863-': 'text/xml', 'content-length': '384', 
    'daad11-4610-9e14-869f72de07a5', 'content-type': 'text/xml', 'content-length': '384',
    'date': 'Thu, 18 Mar 2021 07:08:00 GMT'}, 'RetryAttempts': 0}}

Operation Successful


4. You can verify the stack by going over to AWS console, searching "Cloud Formation" and seeing the name of your lambda function created successfully. 

Shoutout to @jleeboyd for helping with the boto3 script.
ahmadafrasiyab commented 3 years ago
Date Activity Time Spent
03/05/2021 Setting up issue 15 mins
03/08/2021 Researching templates 2 hours
03/12/2021 Setting up boto3 30 mins
03/14/2021 Testing deployment 1 hour
03/17/2021 Creating PR 30 mins
ahmadafrasiyab commented 3 years ago

@toddysm I tried using both pairs of AWS access keys and secrets. My personal ones and the GitHub actions ones however for both of them I get authorization issues. For my own I see this:

image

For GitHub ones I see this:

image

Awaiting your feedback on this.