-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathglobal.yml
More file actions
135 lines (118 loc) · 3.64 KB
/
global.yml
File metadata and controls
135 lines (118 loc) · 3.64 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
AWSTemplateFormatVersion: '2010-09-09'
Description: Global Region Orchestration
Parameters:
Region:
Type: String
Description: Master Account Region
Regions:
Type: CommaDelimitedList
Description: All Account Regions
Conditions:
IsMasterRegion: !Equals
- !Ref AWS::Region
- !Ref Region
Resources:
MasterRegion:
Type: AWS::SSM::Parameter
Properties:
Name: /Global/MasterRegion
Type: String
Value: !Ref Region
Description: "Master AWS Region"
ReplicationRegions:
Type: AWS::SSM::Parameter
Properties:
Name: /Global/Regions
Type: StringList
Value: !Join [ ",", !Ref "Regions" ]
Description: "List of all deployed regions"
RegionRole:
Type: AWS::SSM::Parameter
Properties:
Name: /Global/Role
Type: String
Value: !If
- IsMasterRegion
- Master
- Slave
Description: "Master AWS Region"
GlobalImportValue:
Type: AWS::Lambda::Function
Properties:
FunctionName: GlobalImportValue
Handler: index.handler
Role: !GetAtt GlobalImportValueExecutionRole.Arn
Runtime: nodejs6.10
Code:
# Inline contents of /globalImports.js
ZipFile: |
const response = require("cfn-response");
const AWS = require("aws-sdk");
exports.handler = (event, context) => {
const { SourceRegion, Exports = ['.+'] } = event.ResourceProperties;
const filters = Exports.map(e => new RegExp(e, 'i'));
const id = `custom:cloudformation:${SourceRegion}:exports`;
const cloudformation = new AWS.CloudFormation({ region: SourceRegion });
try {
cloudformation.listExports({}, (err, data) => {
if (err) {
throw err;
} else {
const obj = {};
data.Exports.forEach(({ Name, Value }) => {
const matches = filters.filter(f => f.test(Name));
if (matches.length > 0) obj[Name] = Value;
});
response.send(event, context, response.SUCCESS, obj, id);
}
});
} catch (err) {
console.error(err.message);
response.send(event, context, response.FAILED, {}, id);
}
};
GlobalImportValueLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub "/aws/lambda/${GlobalImportValue}"
RetentionInDays: 1
GlobalImportValueExecutionRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service: !Sub "lambda.${AWS::URLSuffix}"
Action:
- sts:AssumeRole
Path: /
ManagedPolicyArns:
- !Sub "arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
Policies:
- PolicyName: AssumedExecutionRole
PolicyDocument:
Version: '2012-10-17'
Statement:
- Action:
- cloudformation:ListExports
Effect: Allow
Resource:
- "*"
Outputs:
RegionRole:
Description: Describes the role of this region
Value: !GetAtt RegionRole.Value
Export:
Name: RegionRole
MasterRegion:
Description: Master Account Deployment Region
Value: !GetAtt MasterRegion.Value
Export:
Name: MasterRegion
GlobalImportValueToken:
Description: Lambda Function Arn for Global Import
Value: !GetAtt GlobalImportValue.Arn
Export:
Name: GlobalImportValue