forked from galaxyproject/gxy.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lambda.yaml
66 lines (56 loc) · 2.28 KB
/
lambda.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
- name: Deploy Lambda Function
hosts: lambdahosts
tasks:
- name: Create tempdir for Lambda deployment package
ansible.builtin.tempfile:
state: directory
suffix: gxy.io-lambda
register: __gxy_io_tempdir
- name: Register tempdir path
ansible.builtin.set_fact:
gxy_io_tempdir: "{{ __gxy_io_tempdir.path }}"
gxy_io_function_path: "{{ __gxy_io_tempdir.path }}/lambda_function.py"
gxy_io_zip_path: "{{ __gxy_io_tempdir.path }}/lambda_function.zip"
- block:
- name: Template gxy.io Lambda function
ansible.builtin.template:
src: lambda_function.py.j2
dest: "{{ gxy_io_function_path }}"
- name: Create Lambda deployment package (zip)
community.general.archive:
format: zip
path:
- "{{ gxy_io_function_path }}"
dest: "{{ gxy_io_zip_path }}"
- name: Deploy Lambda function
community.aws.lambda:
name: "gxy-io-redirect"
state: present
zip_file: "{{ gxy_io_zip_path }}"
runtime: "python3.9"
role: "{{ gxy_io_lambda_exec_role_arn }}"
handler: "lambda_function.lambda_handler"
region: "us-east-1"
register: __gxy_io_lambda_deploy
- name: Set new ARN fact
set_fact:
gxy_io_lambda_arn: "{{ __gxy_io_lambda_deploy.configuration.function_arn }}"
- name: Update CloudFront distribution with new ARN
community.aws.cloudfront_distribution:
state: present
distribution_id: "{{ gxy_io_cloudfront_distribution_id }}"
default_cache_behavior:
lambda_function_associations:
- event_type: viewer-request
lambda_function_arn: "{{ gxy_io_lambda_arn }}"
# this can fail for a bit due to:
# The function must be in an Active state. The current state for function arn:...:function:gxy-io-redirect:<new-version> is Pending
register: __gxy_io_cloudfront_deploy
until: __gxy_io_cloudfront_deploy is success
retries: 18
delay: 10
always:
- name: Remove tempdir
ansible.builtin.file:
path: "{{ gxy_io_tempdir }}"
state: absent