Skip to content
This repository was archived by the owner on Oct 7, 2025. It is now read-only.

Commit bbc3d9b

Browse files
author
Matej Stajduhar
committed
Updating-lambda-function-handling
1 parent 4b4c46e commit bbc3d9b

File tree

6 files changed

+20
-11
lines changed

6 files changed

+20
-11
lines changed

roles/aws/aws_admin_tools/tasks/lambda_functions.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
timeout: "{{ item.timeout | default(aws_admin_tools.timeout) }}"
2424
role: "{{ aws_iam_role._result[item.resource + '_' + item.name] }}"
2525
runtime: "{{ aws_admin_tools.runtime }}"
26-
function_type: "file"
2726
function_file: "{{ _function_file }}"
2827
s3_bucket: "{{ _general_bucket }}"
2928
s3_bucket_prefix: "lambda-functions"

roles/aws/aws_backup_validation/defaults/main.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ aws_backup_validation:
1010
resources:
1111
- name: ec2_test_instance
1212
type: EC2
13-
function_type: file
1413
lambda_policy:
1514
- "backup:PutRestoreValidationResult"
1615
- "ssm:GetCommandInvocation"
@@ -19,7 +18,6 @@ aws_backup_validation:
1918
- "ec2:DescribeInstances"
2019
- name: rds_test_instance
2120
type: RDS
22-
function_type: file
2321
lambda_policy:
2422
- "backup:PutRestoreValidationResult"
2523
- "ssm:GetCommandInvocation"
@@ -28,12 +26,10 @@ aws_backup_validation:
2826
- "rds:DescribeDBInstances"
2927
- name: aurora_create_instance
3028
type: Aurora
31-
function_type: file
3229
lambda_policy:
3330
- "lambda:InvokeFunction"
3431
- name: aurora_test_instance
3532
type: Aurora
36-
function_type: file
3733
event_pattern: '{ "source": ["aws.rds"], "detail-type": ["RDS DB Instance Event"], "resources": [{ "prefix": "arn:aws:rds:eu-west-1:{{ _acc_id }}:db:restoretest" }], "detail": { "EventID": ["RDS-EVENT-0005"] } }'
3834
lambda_policy:
3935
- "backup:PutRestoreValidationResult"
@@ -43,7 +39,6 @@ aws_backup_validation:
4339
- "rds:DeleteDBInstance"
4440
- name: validation_report
4541
type: Schedule
46-
function_type: file
4742
schedule: "cron(0 0 ? * MON *)"
4843
lambda_policy:
4944
- "backup:ListRestoreJobs"

roles/aws/aws_backup_validation/tasks/main.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
vars:
5050
aws_lambda:
5151
name: "{{ item.name }}"
52-
function_type: "{{ item.function_type }}"
5352
description: "Lambda functions for {{ item.type }} validation."
5453
timeout: "{{ aws_backup_validation.timeout }}"
5554
role: "{{ aws_iam_role._result[item.name + '_lambda'] }}"

roles/aws/aws_backup_validation/templates/aurora_test_instance.py.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def lambda_handler(event, context):
7474
print("Creating script!")
7575
script = """
7676
cat /etc/motd
77-
old_host=$(grep host /home/deploy/.mysql.creds | awk -F= '{{print $2 }}')
77+
old_host={{ '$' }}(grep host /home/deploy/.mysql.creds | awk -F= '{{ '{{' }}print $2 {{ '}}' }}')
7878
sed 's,old_host,{new_host},g' /home/deploy/.mysql.creds >> /home/deploy/.mysql.creds.tmp
7979
mysql --defaults-file=/home/deploy/.mysql.creds.tmp -e "SELECT table_schema 'DB Name', ROUND(SUM(data_length + index_length) / 1024 / 1024, 1) 'DB Size in MB' FROM information_schema.tables GROUP BY table_schema;"
8080
rm /home/deploy/.mysql.creds.tmp

roles/aws/aws_cloudfront_distribution/tasks/create_lambda_function.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
role: "{{ aws_iam_role._result['lambda_edge'] }}"
2727
runtime: "{{ _funct.runtime }}"
2828
function_file: "{{ _ce_provision_build_dir }}/files/{{ _funct.code }}"
29-
functrion_type: "file"
3029
s3_bucket: "codeenigma-{{ _aws_profile }}-general-storage-us-east-1"
3130
s3_bucket_prefix: "lambda-functions"
3231
tags:

roles/aws/aws_lambda/tasks/main.yml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,30 @@
99
tags: []
1010
state: "present"
1111

12+
- name: Check string type using regex.
13+
ansible.builtin.set_fact:
14+
_string_type: >-
15+
{%- if input_string | regex_search('^(https?://|git@)') -%}
16+
url
17+
{%- elif input_string | regex_search('\.zip$', ignorecase=True) -%}
18+
zip
19+
{%- else -%}
20+
single
21+
{%- endif -%}
22+
vars:
23+
input_string: "{{ aws_lambda.function_file }}"
24+
1225
- name: Handle single file.
1326
ansible.builtin.include_tasks: handle_single.yml
14-
when: aws_lambda.function_type is defined and aws_lambda.function_type == 'file'
27+
when: _string_type == 'single'
28+
29+
- name: Handle zip file.
30+
ansible.builtin.include_tasks: handle_zip.yml
31+
when: _string_type == 'zip'
1532

1633
- name: Handle url.
1734
ansible.builtin.include_tasks: handle_url.yml
18-
when: aws_lambda.function_type is defined and aws_lambda.function_type == 'url'
35+
when: _string_type == 'url'
1936

2037
- name: Place Lambda function in S3 bucket.
2138
amazon.aws.s3_object:

0 commit comments

Comments
 (0)