Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #6

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ on:
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AUTHORIZATION: ${{ secrets.AUTHORIZATION }}


jobs:
Expand Down
3 changes: 1 addition & 2 deletions extract_api_data/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
FROM public.ecr.aws/lambda/python:3.12

ENV Authorization=${AUTHORIZATION}

ENV Authorization="Bearer eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJhMTg3NWNjOTlkOGZhY2ZkZTg2OTJkMjk4MTQ5NjQ1YiIsInN1YiI6IjY1OTk5OGU4YmQ1ODhiMDFhOTU3M2FjNyIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.Z0lbJN4SXfdHU9dJRlHGr7hO0HtvZagtMFD7l4L1W6E"
WORKDIR ${LAMBDA_TASK_ROOT}

COPY requirements.txt ./
Expand Down
4 changes: 2 additions & 2 deletions extract_api_data/api_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def extract_api_data(url: str, headers: dict) -> dict:
try:
response = requests.get(url, headers=headers)
if response.status_code == 200:
data = json.loads(response.text)['results']
data = response.json()['results']
logger.info('API data extracted')
return data
except Exception as e:
Expand All @@ -41,6 +41,7 @@ def lambda_handler(event, context):
'https://api.themoviedb.org/3/discover/movie?include_adult='
+ 'false&include_video=false&language=en-US&page=1&sort_by=popularity.desc'
)

headers = {"accept": "application/json", "Authorization": authorization}

today_date = datetime.date.today().strftime("%Y-%m-%d")
Expand All @@ -49,5 +50,4 @@ def lambda_handler(event, context):
key = f"api_data/{today_date}/movies.json"

data = extract_api_data(url, headers)
json_data = json.dumps(data)
upload_to_s3(bucket_name, key, data)
2 changes: 1 addition & 1 deletion terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ resource "aws_iam_role" "lambda_iam_role" {
]
})

managed_policy_arns = ["arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryFullAccess", "arn:aws:iam::aws:policy/AmazonS3FullAccess","arn:aws:iam::aws:policy/CloudWatchEventsFullAccess"]
managed_policy_arns = ["arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryFullAccess", "arn:aws:iam::aws:policy/AmazonS3FullAccess","arn:aws:iam::aws:policy/CloudWatchEventsFullAccess","arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"]
}
Loading