|
1 | 1 | { |
2 | 2 | "Resources": { |
3 | | - "HtmlFunction": { |
4 | | - "Type": "AWS::Lambda::Function", |
| 3 | + "HtmlFunctionIamPermissionTest": { |
| 4 | + "Type": "AWS::Lambda::Permission", |
5 | 5 | "Properties": { |
6 | | - "Code": { |
7 | | - "S3Bucket": "sam-demo-bucket", |
8 | | - "S3Key": "member_portal.zip" |
9 | | - }, |
10 | | - "Handler": "index.gethtml", |
11 | | - "Role": { |
12 | | - "Fn::GetAtt": [ |
13 | | - "HtmlFunctionRole", |
14 | | - "Arn" |
| 6 | + "Action": "lambda:invokeFunction", |
| 7 | + "Principal": "apigateway.amazonaws.com", |
| 8 | + "FunctionName": { |
| 9 | + "Ref": "HtmlFunction" |
| 10 | + }, |
| 11 | + "SourceArn": { |
| 12 | + "Fn::Sub": [ |
| 13 | + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/iam", |
| 14 | + { |
| 15 | + "__Stage__": "*", |
| 16 | + "__ApiId__": { |
| 17 | + "Ref": "HtmlApi" |
| 18 | + } |
| 19 | + } |
15 | 20 | ] |
16 | | - }, |
17 | | - "Runtime": "nodejs4.3", |
18 | | - "Tags": [ |
19 | | - { |
20 | | - "Key": "lambda:createdBy", |
21 | | - "Value": "SAM" |
22 | | - } |
23 | | - ] |
| 21 | + } |
24 | 22 | } |
25 | | - }, |
| 23 | + }, |
26 | 24 | "HtmlFunctionRole": { |
27 | | - "Type": "AWS::IAM::Role", |
| 25 | + "Type": "AWS::IAM::Role", |
28 | 26 | "Properties": { |
| 27 | + "ManagedPolicyArns": [ |
| 28 | + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" |
| 29 | + ], |
29 | 30 | "AssumeRolePolicyDocument": { |
30 | | - "Version": "2012-10-17", |
| 31 | + "Version": "2012-10-17", |
31 | 32 | "Statement": [ |
32 | 33 | { |
33 | 34 | "Action": [ |
34 | 35 | "sts:AssumeRole" |
35 | | - ], |
36 | | - "Effect": "Allow", |
| 36 | + ], |
| 37 | + "Effect": "Allow", |
37 | 38 | "Principal": { |
38 | 39 | "Service": [ |
39 | 40 | "lambda.amazonaws.com" |
40 | 41 | ] |
41 | 42 | } |
42 | 43 | } |
43 | 44 | ] |
44 | | - }, |
45 | | - "ManagedPolicyArns": [ |
46 | | - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" |
47 | | - ] |
| 45 | + } |
48 | 46 | } |
49 | | - }, |
50 | | - "HtmlFunctionGetHtmlPermissionTest": { |
51 | | - "Type": "AWS::Lambda::Permission", |
| 47 | + }, |
| 48 | + "HtmlApiProdStage": { |
| 49 | + "Type": "AWS::ApiGateway::Stage", |
52 | 50 | "Properties": { |
53 | | - "Action": "lambda:invokeFunction", |
54 | | - "FunctionName": { |
55 | | - "Ref": "HtmlFunction" |
56 | | - }, |
57 | | - "Principal": "apigateway.amazonaws.com", |
58 | | - "SourceArn": { |
59 | | - "Fn::Sub": [ |
60 | | - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", |
61 | | - { |
62 | | - "__ApiId__": "HtmlApi", |
63 | | - "__Stage__": "*" |
64 | | - } |
65 | | - ] |
66 | | - } |
| 51 | + "DeploymentId": { |
| 52 | + "Ref": "HtmlApiDeployment47f78fe7d9" |
| 53 | + }, |
| 54 | + "RestApiId": { |
| 55 | + "Ref": "HtmlApi" |
| 56 | + }, |
| 57 | + "StageName": "Prod" |
67 | 58 | } |
68 | | - }, |
69 | | - "HtmlFunctionGetHtmlPermissionProd": { |
70 | | - "Type": "AWS::Lambda::Permission", |
| 59 | + }, |
| 60 | + "HtmlFunctionIamPermissionProd": { |
| 61 | + "Type": "AWS::Lambda::Permission", |
71 | 62 | "Properties": { |
72 | | - "Action": "lambda:invokeFunction", |
| 63 | + "Action": "lambda:invokeFunction", |
| 64 | + "Principal": "apigateway.amazonaws.com", |
73 | 65 | "FunctionName": { |
74 | 66 | "Ref": "HtmlFunction" |
75 | | - }, |
76 | | - "Principal": "apigateway.amazonaws.com", |
| 67 | + }, |
77 | 68 | "SourceArn": { |
78 | 69 | "Fn::Sub": [ |
79 | | - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", |
| 70 | + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/iam", |
80 | 71 | { |
81 | | - "__ApiId__": "HtmlApi", |
82 | | - "__Stage__": "Prod" |
| 72 | + "__Stage__": "Prod", |
| 73 | + "__ApiId__": { |
| 74 | + "Ref": "HtmlApi" |
| 75 | + } |
83 | 76 | } |
84 | 77 | ] |
85 | 78 | } |
86 | 79 | } |
87 | | - }, |
| 80 | + }, |
88 | 81 | "HtmlApi": { |
89 | | - "Type": "AWS::ApiGateway::RestApi", |
| 82 | + "Type": "AWS::ApiGateway::RestApi", |
90 | 83 | "Properties": { |
91 | 84 | "Body": { |
92 | 85 | "info": { |
93 | | - "version": "1.0", |
| 86 | + "version": "1.0", |
94 | 87 | "title": { |
95 | 88 | "Ref": "AWS::StackName" |
96 | 89 | } |
97 | | - }, |
| 90 | + }, |
98 | 91 | "paths": { |
99 | | - "/": { |
| 92 | + "/iam": { |
100 | 93 | "get": { |
| 94 | + "requestBody": { |
| 95 | + "content": { |
| 96 | + "application/json": { |
| 97 | + "schema": { |
| 98 | + "$ref": "#/components/schemas/user" |
| 99 | + } |
| 100 | + } |
| 101 | + }, |
| 102 | + "required": true |
| 103 | + }, |
101 | 104 | "x-amazon-apigateway-integration": { |
102 | | - "type": "aws_proxy", |
103 | | - "httpMethod": "POST", |
| 105 | + "httpMethod": "POST", |
| 106 | + "type": "aws_proxy", |
104 | 107 | "uri": { |
105 | 108 | "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" |
| 109 | + }, |
| 110 | + "credentials": "arn:aws:iam::*:user/*" |
| 111 | + }, |
| 112 | + "security": [ |
| 113 | + { |
| 114 | + "AWS_IAM": [] |
106 | 115 | } |
107 | | - }, |
108 | | - "responses": {}, |
| 116 | + ], |
| 117 | + "responses": {} |
| 118 | + } |
| 119 | + }, |
| 120 | + "/": { |
| 121 | + "get": { |
109 | 122 | "requestBody": { |
110 | 123 | "content": { |
111 | 124 | "application/json": { |
112 | 125 | "schema": { |
113 | 126 | "$ref": "#/components/schemas/user" |
114 | 127 | } |
115 | 128 | } |
116 | | - }, |
| 129 | + }, |
117 | 130 | "required": true |
118 | | - } |
| 131 | + }, |
| 132 | + "x-amazon-apigateway-integration": { |
| 133 | + "httpMethod": "POST", |
| 134 | + "type": "aws_proxy", |
| 135 | + "uri": { |
| 136 | + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" |
| 137 | + } |
| 138 | + }, |
| 139 | + "responses": {} |
119 | 140 | } |
120 | 141 | } |
121 | | - }, |
122 | | - "openapi": "3.0.1", |
| 142 | + }, |
| 143 | + "openapi": "3.0.1", |
123 | 144 | "components": { |
| 145 | + "securitySchemes": { |
| 146 | + "AWS_IAM": { |
| 147 | + "x-amazon-apigateway-authtype": "awsSigv4", |
| 148 | + "type": "apiKey", |
| 149 | + "name": "Authorization", |
| 150 | + "in": "header" |
| 151 | + } |
| 152 | + }, |
124 | 153 | "schemas": { |
125 | 154 | "user": { |
126 | | - "type": "object", |
| 155 | + "type": "object", |
127 | 156 | "properties": { |
128 | 157 | "username": { |
129 | 158 | "type": "string" |
|
134 | 163 | } |
135 | 164 | } |
136 | 165 | } |
137 | | - }, |
138 | | - "HtmlApiDeployment1cc40869ce": { |
139 | | - "Type": "AWS::ApiGateway::Deployment", |
| 166 | + }, |
| 167 | + "HtmlApiDeployment47f78fe7d9": { |
| 168 | + "Type": "AWS::ApiGateway::Deployment", |
140 | 169 | "Properties": { |
141 | | - "Description": "RestApi deployment id: 1cc40869cebf8364cbef858c24289beee3338228", |
142 | 170 | "RestApiId": { |
143 | 171 | "Ref": "HtmlApi" |
| 172 | + }, |
| 173 | + "Description": "RestApi deployment id: 47f78fe7d91eb5d2070674ad77943842c49dab89" |
| 174 | + } |
| 175 | + }, |
| 176 | + "HtmlFunctionGetHtmlPermissionTest": { |
| 177 | + "Type": "AWS::Lambda::Permission", |
| 178 | + "Properties": { |
| 179 | + "Action": "lambda:invokeFunction", |
| 180 | + "Principal": "apigateway.amazonaws.com", |
| 181 | + "FunctionName": { |
| 182 | + "Ref": "HtmlFunction" |
| 183 | + }, |
| 184 | + "SourceArn": { |
| 185 | + "Fn::Sub": [ |
| 186 | + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", |
| 187 | + { |
| 188 | + "__Stage__": "*", |
| 189 | + "__ApiId__": "HtmlApi" |
| 190 | + } |
| 191 | + ] |
144 | 192 | } |
145 | 193 | } |
146 | | - }, |
147 | | - "HtmlApiProdStage": { |
148 | | - "Type": "AWS::ApiGateway::Stage", |
| 194 | + }, |
| 195 | + "HtmlFunctionGetHtmlPermissionProd": { |
| 196 | + "Type": "AWS::Lambda::Permission", |
149 | 197 | "Properties": { |
150 | | - "DeploymentId": { |
151 | | - "Ref": "HtmlApiDeployment1cc40869ce" |
152 | | - }, |
153 | | - "RestApiId": { |
154 | | - "Ref": "HtmlApi" |
155 | | - }, |
156 | | - "StageName": "Prod" |
| 198 | + "Action": "lambda:invokeFunction", |
| 199 | + "Principal": "apigateway.amazonaws.com", |
| 200 | + "FunctionName": { |
| 201 | + "Ref": "HtmlFunction" |
| 202 | + }, |
| 203 | + "SourceArn": { |
| 204 | + "Fn::Sub": [ |
| 205 | + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", |
| 206 | + { |
| 207 | + "__Stage__": "Prod", |
| 208 | + "__ApiId__": "HtmlApi" |
| 209 | + } |
| 210 | + ] |
| 211 | + } |
| 212 | + } |
| 213 | + }, |
| 214 | + "HtmlFunction": { |
| 215 | + "Type": "AWS::Lambda::Function", |
| 216 | + "Properties": { |
| 217 | + "Handler": "index.gethtml", |
| 218 | + "Code": { |
| 219 | + "S3Bucket": "sam-demo-bucket", |
| 220 | + "S3Key": "member_portal.zip" |
| 221 | + }, |
| 222 | + "Role": { |
| 223 | + "Fn::GetAtt": [ |
| 224 | + "HtmlFunctionRole", |
| 225 | + "Arn" |
| 226 | + ] |
| 227 | + }, |
| 228 | + "Runtime": "nodejs4.3", |
| 229 | + "Tags": [ |
| 230 | + { |
| 231 | + "Value": "SAM", |
| 232 | + "Key": "lambda:createdBy" |
| 233 | + } |
| 234 | + ] |
157 | 235 | } |
158 | 236 | } |
159 | 237 | } |
|
0 commit comments