Guest User

Untitled

a guest
Jun 6th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.90 KB | None | 0 0
  1. # This template is a Cloud Formation template, that has AWS Sam seamlessly mixed in
  2. # It is extremely powerful as you will see!
  3.  
  4. # This is a template of Lambda & RDS, publically available (so no private VPC)
  5. AWSTemplateFormatVersion: 2010-09-09
  6. Transform: AWS::Serverless-2016-10-31 # This is to tell cloudformation we need to transform this template, as it has SAM!
  7.  
  8. Description: Severless set up with an RDS
  9. ######## ### ######## ### ## ##
  10. ## ## ## ## ## ## ## ## ### ###
  11. ## ## ## ## ## ## ## ## #### ####
  12. ######## ## ## ######## ## ## ## ### ##
  13. ## ######### ## ## ######### ## ##
  14. ## ## ## ## ## ## ## ## ##
  15. ## ## ## ## ## ## ## ## ##
  16. Parameters:
  17. dbUserPassword:
  18. NoEcho: true
  19. Type: String
  20. dbUserName:
  21. NoEcho: true
  22. Type: String
  23. DbSize:
  24. Type: String
  25. Default: db.t2.small
  26. ## Globals is unique to AWS Sam and is not featured in Cloudformation
  27. ## These Globals under Function are passed to each AWS::Serverless::Function as properties
  28. Globals:
  29. Function:
  30. Runtime: go1.x
  31. Timeout: 10
  32. Tracing: Active
  33. Tags:
  34. demo: true
  35. Environment:
  36. Variables:
  37. MY_SQL_URI: !Join ['', [!Ref dbUserName, ':', !Ref dbUserPassword, '@(', !GetAtt DatabaseCluster.Endpoint.Address, ':', !GetAtt DatabaseCluster.Endpoint.Port, ')/mydb']]
  38. # The powerful intrinsic function Join, here we join a db connection string and make it a global
  39. # So every lambda function can access it right away!
  40.  
  41. ## ### ## ## ######## ######## ###
  42. ## ## ## ### ### ## ## ## ## ## ##
  43. ## ## ## #### #### ## ## ## ## ## ##
  44. ## ## ## ## ### ## ######## ## ## ## ##
  45. ## ######### ## ## ## ## ## ## #########
  46. ## ## ## ## ## ## ## ## ## ## ##
  47. ######## ## ## ## ## ######## ######## ## ##
  48. # The following sections is AWS Sam
  49. # It ties together Lambda functions so they are easy to deploy as you will see
  50. Resources:
  51. Write:
  52. Type: AWS::Serverless::Function # This type Serverless::Function is unique to Sam
  53. Properties:
  54. Policies:
  55. - AWSXrayWriteOnlyAccess
  56. Handler: dist/handler/write # Ofcourse we tell need to mention where the code is
  57. Events: # It lets you define events that trigger your lambda function
  58. GetEvent:
  59. Type: Api # This is an API Gateway event, it automically handles all in & outs of setting up an API gateway with Lambda!
  60. Properties:
  61. Path: /write
  62. Method: get
  63. Read:
  64. Type: AWS::Serverless::Function
  65. Properties:
  66. Policies:
  67. - AWSXrayWriteOnlyAccess
  68. Handler: dist/handler/read
  69. Events:
  70. GetEvent:
  71. Type: Api
  72. Properties:
  73. Path: /read
  74. Method: get
  75.  
  76. ######## ######## ######
  77. ## ## ## ## ## ##
  78. ## ## ## ## ##
  79. ######## ## ## ######
  80. ## ## ## ## ##
  81. ## ## ## ## ## ##
  82. ## ## ######## ######
  83.  
  84. PublicDatabaseSubnetGroup:
  85. Type: AWS::RDS::DBSubnetGroup
  86. Properties:
  87. DBSubnetGroupDescription: CloudFormation managed DB subnet group.
  88. SubnetIds: !Split [ ',', !ImportValue LambdaVPCExperiementPublicSubnets]
  89. # More powerful intrinsic functions, we import the Public Subnets from another stack & split it into a list like SubnetIds require
  90. DatabaseCluster:
  91. Type: AWS::RDS::DBCluster
  92. Properties:
  93. MasterUsername: !Ref dbUserName
  94. MasterUserPassword: !Ref dbUserPassword
  95. Engine: aurora
  96. DBSubnetGroupName: !Ref PublicDatabaseSubnetGroup
  97. DatabasePrimaryInstance:
  98. Type: AWS::RDS::DBInstance
  99. Properties:
  100. Engine: aurora
  101. DBClusterIdentifier: !Ref "DatabaseCluster"
  102. DBInstanceClass: !Ref DbSize
  103. DBSubnetGroupName: !Ref PublicDatabaseSubnetGroup
  104. PubliclyAccessible: true
Add Comment
Please, Sign In to add comment