Advertisement
Guest User

Untitled

a guest
Aug 26th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.07 KB | None | 0 0
  1. {
  2. "AWSTemplateFormatVersion": "2010-09-09",
  3. "Description": "Lambda resource stack creation using Amplify CLI",
  4. "Parameters": {
  5. "env": {
  6. "Type": "String"
  7. },
  8. "DynamoDBPhotoTableArn": {
  9. "Type": "String",
  10. "Default": "DYNAMODB_PHOTO_TABLE_ARN_PLACEHOLDER"
  11. }
  12. },
  13. "Conditions": {
  14. "ShouldNotCreateEnvResources": {
  15. "Fn::Equals": [
  16. {
  17. "Ref": "env"
  18. },
  19. "NONE"
  20. ]
  21. }
  22. },
  23. "Resources": {
  24. "LambdaFunction": {
  25. "Type": "AWS::Lambda::Function",
  26. "Metadata": {
  27. "aws:asset:path": "./src",
  28. "aws:asset:property": "Code"
  29. },
  30. "Properties": {
  31. "Handler": "index.handler",
  32. "FunctionName": {
  33. "Fn::If": [
  34. "ShouldNotCreateEnvResources",
  35. "S3_TRIGGER_NAME_PLACEHOLDER",
  36. {
  37. "Fn::Join": [
  38. "",
  39. [
  40. "S3_TRIGGER_NAME_PLACEHOLDER",
  41. "-",
  42. {
  43. "Ref": "env"
  44. }
  45. ]
  46. ]
  47. }
  48. ]
  49. },
  50. "Environment": {
  51. "Variables": {
  52. "ENV": {
  53. "Ref": "env"
  54. },
  55. "THUMBNAIL_WIDTH": "80",
  56. "THUMBNAIL_HEIGHT": "80",
  57. "DYNAMODB_PHOTOS_TABLE_ARN": { "Ref" : "DynamoDBPhotoTableArn" }
  58. }
  59. },
  60. "Role": {
  61. "Fn::GetAtt": [
  62. "LambdaExecutionRole",
  63. "Arn"
  64. ]
  65. },
  66. "Runtime": "nodejs8.10",
  67. "Timeout": "25"
  68. }
  69. },
  70. "LambdaExecutionRole": {
  71. "Type": "AWS::IAM::Role",
  72. "Properties": {
  73. "RoleName": {
  74. "Fn::If": [
  75. "ShouldNotCreateEnvResources",
  76. "S3_TRIGGER_NAME_PLACEHOLDERLambdaRole66924eb7",
  77. {
  78. "Fn::Join": [
  79. "",
  80. [
  81. "S3_TRIGGER_NAME_PLACEHOLDERLambdaRole66924eb7",
  82. "-",
  83. {
  84. "Ref": "env"
  85. }
  86. ]
  87. ]
  88. }
  89. ]
  90. },
  91. "AssumeRolePolicyDocument": {
  92. "Version": "2012-10-17",
  93. "Statement": [
  94. {
  95. "Effect": "Allow",
  96. "Principal": {
  97. "Service": [
  98. "lambda.amazonaws.com"
  99. ]
  100. },
  101. "Action": [
  102. "sts:AssumeRole"
  103. ]
  104. }
  105. ]
  106. }
  107. }
  108. },
  109. "lambdaexecutionpolicy": {
  110. "DependsOn": [
  111. "LambdaExecutionRole"
  112. ],
  113. "Type": "AWS::IAM::Policy",
  114. "Properties": {
  115. "PolicyName": "lambda-execution-policy",
  116. "Roles": [
  117. {
  118. "Ref": "LambdaExecutionRole"
  119. }
  120. ],
  121. "PolicyDocument": {
  122. "Version": "2012-10-17",
  123. "Statement": [
  124. {
  125. "Effect": "Allow",
  126. "Action": [
  127. "logs:CreateLogGroup",
  128. "logs:CreateLogStream",
  129. "logs:PutLogEvents"
  130. ],
  131. "Resource": {
  132. "Fn::Sub": [
  133. "arn:aws:logs:${region}:${account}:log-group:/aws/lambda/${lambda}:log-stream:*",
  134. {
  135. "region": {
  136. "Ref": "AWS::Region"
  137. },
  138. "account": {
  139. "Ref": "AWS::AccountId"
  140. },
  141. "lambda": {
  142. "Ref": "LambdaFunction"
  143. }
  144. }
  145. ]
  146. }
  147. }
  148. ]
  149. }
  150. }
  151. },
  152. "AllPrivsForDynamo": {
  153. "DependsOn": [
  154. "LambdaExecutionRole"
  155. ],
  156. "Type": "AWS::IAM::Policy",
  157. "Properties": {
  158. "PolicyName": "AllPrivsForDynamo",
  159. "Roles": [
  160. {
  161. "Ref": "LambdaExecutionRole"
  162. }
  163. ],
  164. "PolicyDocument": {
  165. "Version": "2012-10-17",
  166. "Statement": [
  167. {
  168. "Effect": "Allow",
  169. "Action": [
  170. "dynamodb:*"
  171. ],
  172. "Resource": { "Ref" : "DynamoDBPhotoTableArn" }
  173. }
  174. ]
  175. }
  176. }
  177. },
  178. "RekognitionDetectLabels": {
  179. "DependsOn": [
  180. "LambdaExecutionRole"
  181. ],
  182. "Type": "AWS::IAM::Policy",
  183. "Properties": {
  184. "PolicyName": "RekognitionDetectLabels",
  185. "Roles": [
  186. {
  187. "Ref": "LambdaExecutionRole"
  188. }
  189. ],
  190. "PolicyDocument": {
  191. "Version": "2012-10-17",
  192. "Statement": [
  193. {
  194. "Effect": "Allow",
  195. "Action": [
  196. "rekognition:detectLabels"
  197. ],
  198. "Resource": "*"
  199. }
  200. ]
  201. }
  202. }
  203. }
  204. },
  205. "Outputs": {
  206. "Name": {
  207. "Value": {
  208. "Ref": "LambdaFunction"
  209. }
  210. },
  211. "Arn": {
  212. "Value": {
  213. "Fn::GetAtt": [
  214. "LambdaFunction",
  215. "Arn"
  216. ]
  217. }
  218. },
  219. "Region": {
  220. "Value": {
  221. "Ref": "AWS::Region"
  222. }
  223. },
  224. "LambdaExecutionRole": {
  225. "Value": {
  226. "Ref": "LambdaExecutionRole"
  227. }
  228. }
  229. }
  230. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement