From 7258caf2550b5dab0cca116f732b390b2f89039b Mon Sep 17 00:00:00 2001 From: Khalid Ahmed Date: Sat, 16 Dec 2023 21:52:25 -0500 Subject: [PATCH 1/5] added readme for notes --- README.md | 18 +++--------------- build/Notes/README.md | 2 ++ 2 files changed, 5 insertions(+), 15 deletions(-) create mode 100644 build/Notes/README.md diff --git a/README.md b/README.md index 603f5a22..aa08ec89 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # DEVELOPER PORTFOLIO -## Sample Website +## Website A live demo is already available via this [link](https://www.khalidahmedportfolio.com/) @@ -8,18 +8,6 @@ A live demo is already available via this [link](https://www.khalidahmedportfoli **Client:** HTML, CSS, Vanilla JavaSCript -## Tools Used +**Server** AWS S3, Route 53 and ACM, AWS Lambda, DynamoDB -Below are are list of tools used, and the precise things they were used for: - -- [Ion Icons](https://ionic.io/ionicons) for hambuger menu bar -- [Drawkit](https://www.drawkit.io/) for Jane Doe illustration -- [Icon8](https://icons8.com/) for animated icons and skills icons -- [Animate CSS](https://animate.style/) for Jane Doe's bio text animation -- [Formspree](https://formspree.io/) for contact form submission and straight delivery to Gmail - -## Folder Structure - -The index.html and readme files are in the root folder, alongside the screenshot included in the readme. - -The assets folder contains the CSS and JavaScript files, all images and icons used, in their respective folders. +Detailed Notes on struggles and things observed while doing this project here \ No newline at end of file diff --git a/build/Notes/README.md b/build/Notes/README.md new file mode 100644 index 00000000..fdd15598 --- /dev/null +++ b/build/Notes/README.md @@ -0,0 +1,2 @@ +# Observations and Notes While Doing the Cloud Resume Challenge + From 85e880f75c91bb476dca8bf4958bbb19409584d4 Mon Sep 17 00:00:00 2001 From: Khalid Ahmed Date: Sun, 17 Dec 2023 18:49:38 -0500 Subject: [PATCH 2/5] added IaC and slight readme update --- .github/workflows/aws-iac-update.yml | 34 +++++++++++++++++++ README.md | 8 +++-- .../dynamodb_table_template.yaml | 17 ++++++++++ aws_iac_templates/iam_role_template.yaml | 33 ++++++++++++++++++ .../lambda_function/lambda_function.py | 22 ++++++++++++ .../lambda_function_template.yaml | 14 ++++++++ 6 files changed, 125 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/aws-iac-update.yml create mode 100644 aws_iac_templates/dynamodb_table_template.yaml create mode 100644 aws_iac_templates/iam_role_template.yaml create mode 100644 aws_iac_templates/lambda_function/lambda_function.py create mode 100644 aws_iac_templates/lambda_function_template.yaml diff --git a/.github/workflows/aws-iac-update.yml b/.github/workflows/aws-iac-update.yml new file mode 100644 index 00000000..0e6197bf --- /dev/null +++ b/.github/workflows/aws-iac-update.yml @@ -0,0 +1,34 @@ +name: aws-s3-push-data + +on: + push: + branches: + - main + paths: + - '/aws_iac_templates/*' + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - name: Checkout GitHub repo + uses: actions/checkout@v2 + + - name: Setup AWS CLI + uses: aws-actions/configure-aws-credentials@v2 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: us-east-1 + + - name: Update DynamoDB table + run: | + sam deploy --template-file ./aws_iac_templates/dynamodb_table_template.yaml --stack-name dynamoDBStack --region us-east-1 --profile iamadmin-production + + - name: Update Lambda function + run: | + sam deploy --template-file ./aws_iac_templates/lambda_function_template.yaml --stack-name visitCounter2Stack --region us-east-1 --profile iamadmin-production --s3-bucket khalidtestbucket --capabilities CAPABILITY_IAM + + - name: Update IAM Role + run: | + sam deploy --template-file ./aws_iac_templates/iam_role_template.yaml --stack-name iamRoleStack --region us-east-1 --profile iamadmin-production --capabilities CAPABILITY_IAM diff --git a/README.md b/README.md index aa08ec89..d2a3a4fa 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,15 @@ # DEVELOPER PORTFOLIO +Following the common project called the [cloud resume challenge](https://cloudresumechallenge.dev/docs/the-challenge/aws/) I created my portfolio using a variety of technologies. I had fun doing this project and had a few struggles along the way. I was able to learn new skills and show them here. + ## Website -A live demo is already available via this [link](https://www.khalidahmedportfolio.com/) +A live demo is already available via https://www.khalidahmedportfolio.com/ ## Tech Stack **Client:** HTML, CSS, Vanilla JavaSCript -**Server** AWS S3, Route 53 and ACM, AWS Lambda, DynamoDB +**Server** AWS S3, Route 53 and ACM, AWS Lambda, DynamoDB, IAM, AWS SAM/Cloudformation -Detailed Notes on struggles and things observed while doing this project here \ No newline at end of file +### Detailed Notes on struggles and things observed while doing the cloud resume project [can be found here](https://github.com/ahmedk2/khalidportfolio/blob/main/build/Notes/README.md) \ No newline at end of file diff --git a/aws_iac_templates/dynamodb_table_template.yaml b/aws_iac_templates/dynamodb_table_template.yaml new file mode 100644 index 00000000..634412fc --- /dev/null +++ b/aws_iac_templates/dynamodb_table_template.yaml @@ -0,0 +1,17 @@ +AWSTemplateFormatVersion: '2010-09-09' +Transform: 'AWS::Serverless-2016-10-31' + +Resources: + MyDynamoDBTable: + Type: 'AWS::DynamoDB::Table' + Properties: + TableName: cloudresume2 + AttributeDefinitions: + - AttributeName: id + AttributeType: S + KeySchema: + - AttributeName: id + KeyType: HASH + ProvisionedThroughput: + ReadCapacityUnits: 5 + WriteCapacityUnits: 5 diff --git a/aws_iac_templates/iam_role_template.yaml b/aws_iac_templates/iam_role_template.yaml new file mode 100644 index 00000000..8b659ba9 --- /dev/null +++ b/aws_iac_templates/iam_role_template.yaml @@ -0,0 +1,33 @@ +AWSTemplateFormatVersion: '2010-09-09' + +Resources: + LambdaExecutionRole: + Type: 'AWS::IAM::Role' + Properties: + AssumeRolePolicyDocument: + Version: '2012-10-17' + Statement: + - Effect: 'Allow' + Principal: + Service: 'lambda.amazonaws.com' + Action: 'sts:AssumeRole' + Policies: + - PolicyName: DynamoDBPolicy + PolicyDocument: + Version: '2012-10-17' + Statement: + - Effect: 'Allow' + Action: + - 'dynamodb:PutItem' + - 'dynamodb:GetItem' + - 'dynamodb:UpdateItem' + Resource: 'arn:aws:dynamodb:us-east-1:210741841791:table/cloudresume2' + - Effect: 'Allow' + Action: + - 'logs:CreateLogGroup' + Resource: 'arn:aws:logs:us-east-1:210741841791:*' + - Effect: 'Allow' + Action: + - 'logs:CreateLogStream' + - 'logs:PutLogEvents' + Resource: 'arn:aws:logs:us-east-1:210741841791:log-group:/aws/lambda/visitCounter2:*' \ No newline at end of file diff --git a/aws_iac_templates/lambda_function/lambda_function.py b/aws_iac_templates/lambda_function/lambda_function.py new file mode 100644 index 00000000..c6680804 --- /dev/null +++ b/aws_iac_templates/lambda_function/lambda_function.py @@ -0,0 +1,22 @@ +import json +import boto3 + +dynamodb = boto3.resource('dynamodb') +table = dynamodb.Table('cloudresume2') + + +def lambda_handler(event, context): + response = table.get_item(Key={ + 'id': '1' + }) + #print(response) + visits = response['Item']['visits'] + visits = visits + 1 + #print(visits) + response = table.put_item(Item={ + 'id':'1', + 'visits': visits + }) + + #return response + return visits diff --git a/aws_iac_templates/lambda_function_template.yaml b/aws_iac_templates/lambda_function_template.yaml new file mode 100644 index 00000000..ca47ac76 --- /dev/null +++ b/aws_iac_templates/lambda_function_template.yaml @@ -0,0 +1,14 @@ +AWSTemplateFormatVersion: '2010-09-09' +Transform: 'AWS::Serverless-2016-10-31' + +Resources: + VisitCounter2Function: + Type: 'AWS::Serverless::Function' + Properties: + Handler: lambda_function.lambda_handler + Runtime: python3.8 + CodeUri: ./lambda_function + Timeout: 10 + Policies: + - DynamoDBCrudPolicy: + TableName: cloudresume2 From 410bfde0e0e64f4f2c8dbfc8a62c9b6a91e1e2fa Mon Sep 17 00:00:00 2001 From: Khalid Ahmed Date: Sun, 17 Dec 2023 18:55:00 -0500 Subject: [PATCH 3/5] edited name of job --- .github/workflows/aws-iac-update.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/aws-iac-update.yml b/.github/workflows/aws-iac-update.yml index 0e6197bf..3b0c1d9a 100644 --- a/.github/workflows/aws-iac-update.yml +++ b/.github/workflows/aws-iac-update.yml @@ -1,4 +1,4 @@ -name: aws-s3-push-data +name: aws-iac-update on: push: From 1d92538a83d441f3e07f8d06b507491e6c722835 Mon Sep 17 00:00:00 2001 From: Khalid Ahmed Date: Sun, 17 Dec 2023 18:56:54 -0500 Subject: [PATCH 4/5] edited templates to trigger job --- aws_iac_templates/dynamodb_table_template.yaml | 2 +- aws_iac_templates/iam_role_template.yaml | 2 +- aws_iac_templates/lambda_function_template.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/aws_iac_templates/dynamodb_table_template.yaml b/aws_iac_templates/dynamodb_table_template.yaml index 634412fc..daedbc0f 100644 --- a/aws_iac_templates/dynamodb_table_template.yaml +++ b/aws_iac_templates/dynamodb_table_template.yaml @@ -5,7 +5,7 @@ Resources: MyDynamoDBTable: Type: 'AWS::DynamoDB::Table' Properties: - TableName: cloudresume2 + TableName: cloudresume3 AttributeDefinitions: - AttributeName: id AttributeType: S diff --git a/aws_iac_templates/iam_role_template.yaml b/aws_iac_templates/iam_role_template.yaml index 8b659ba9..5a4312eb 100644 --- a/aws_iac_templates/iam_role_template.yaml +++ b/aws_iac_templates/iam_role_template.yaml @@ -21,7 +21,7 @@ Resources: - 'dynamodb:PutItem' - 'dynamodb:GetItem' - 'dynamodb:UpdateItem' - Resource: 'arn:aws:dynamodb:us-east-1:210741841791:table/cloudresume2' + Resource: 'arn:aws:dynamodb:us-east-1:210741841791:table/cloudresume3' - Effect: 'Allow' Action: - 'logs:CreateLogGroup' diff --git a/aws_iac_templates/lambda_function_template.yaml b/aws_iac_templates/lambda_function_template.yaml index ca47ac76..36c63d47 100644 --- a/aws_iac_templates/lambda_function_template.yaml +++ b/aws_iac_templates/lambda_function_template.yaml @@ -11,4 +11,4 @@ Resources: Timeout: 10 Policies: - DynamoDBCrudPolicy: - TableName: cloudresume2 + TableName: cloudresume3 From e432c10d0ac6d007ac9cb2f8ee6a01da96d90586 Mon Sep 17 00:00:00 2001 From: Khalid Ahmed Date: Sun, 17 Dec 2023 19:10:58 -0500 Subject: [PATCH 5/5] updated actions to run on path changes after push event --- .github/workflows/aws-iac-update.yml | 10 +++++----- .github/workflows/aws-s3-push.yml | 3 ++- {build/Notes => Notes}/README.md | 0 3 files changed, 7 insertions(+), 6 deletions(-) rename {build/Notes => Notes}/README.md (100%) diff --git a/.github/workflows/aws-iac-update.yml b/.github/workflows/aws-iac-update.yml index 3b0c1d9a..2c500a14 100644 --- a/.github/workflows/aws-iac-update.yml +++ b/.github/workflows/aws-iac-update.yml @@ -5,10 +5,10 @@ on: branches: - main paths: - - '/aws_iac_templates/*' + - 'aws_iac_templates/**' jobs: - deploy: + Deploy-Iac-To-AWS: runs-on: ubuntu-latest steps: - name: Checkout GitHub repo @@ -23,12 +23,12 @@ jobs: - name: Update DynamoDB table run: | - sam deploy --template-file ./aws_iac_templates/dynamodb_table_template.yaml --stack-name dynamoDBStack --region us-east-1 --profile iamadmin-production + sam deploy --template-file ./aws_iac_templates/dynamodb_table_template.yaml --stack-name dynamoDBStack --region us-east-1 - name: Update Lambda function run: | - sam deploy --template-file ./aws_iac_templates/lambda_function_template.yaml --stack-name visitCounter2Stack --region us-east-1 --profile iamadmin-production --s3-bucket khalidtestbucket --capabilities CAPABILITY_IAM + sam deploy --template-file ./aws_iac_templates/lambda_function_template.yaml --stack-name visitCounter2Stack --region us-east-1 --s3-bucket khalidtestbucket --capabilities CAPABILITY_IAM - name: Update IAM Role run: | - sam deploy --template-file ./aws_iac_templates/iam_role_template.yaml --stack-name iamRoleStack --region us-east-1 --profile iamadmin-production --capabilities CAPABILITY_IAM + sam deploy --template-file ./aws_iac_templates/iam_role_template.yaml --stack-name iamRoleStack --region us-east-1 --capabilities CAPABILITY_IAM diff --git a/.github/workflows/aws-s3-push.yml b/.github/workflows/aws-s3-push.yml index f5dfca0f..1dfea1eb 100644 --- a/.github/workflows/aws-s3-push.yml +++ b/.github/workflows/aws-s3-push.yml @@ -4,7 +4,8 @@ on: push: branches: - main - + paths: + - 'build/**' jobs: deploy: runs-on: ubuntu-latest diff --git a/build/Notes/README.md b/Notes/README.md similarity index 100% rename from build/Notes/README.md rename to Notes/README.md