Guest User

Untitled

a guest
Nov 15th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.53 KB | None | 0 0
  1. {
  2. "schemaVersion": "0.3",
  3. "assumeRole": "{{ AutomationAssumeRole }}",
  4. "description": "Disable Termination Protection of Instance",
  5. "parameters": {
  6. "InstanceId": {
  7. "type": "String",
  8. "description": "(Required) The ID of the instance."
  9. },
  10. "LambdaAssumeRole": {
  11. "default": "",
  12. "type": "String",
  13. "description": "(Optional) The ARN of the role assumed by lambda"
  14. },
  15. "AutomationAssumeRole": {
  16. "default": "",
  17. "type": "String",
  18. "description": "(Optional) The ARN of the role that allows Automation to perform the actions on your behalf. "
  19. }
  20. },
  21. "mainSteps": [
  22. {
  23. "action": "aws:createStack",
  24. "inputs": {
  25. "StackName": "DisableProtectionInstanceStack{{automation:EXECUTION_ID}}",
  26. "TemplateBody": "AWSTemplateFormatVersion: '2010-09-09'\nConditions:\n LambdaAssumeRoleNotSpecified:\n Fn::Or:\n - Fn::Equals:\n - {Ref: LambdaRoleArn}\n - ''\n - Fn::Equals:\n - {Ref: LambdaRoleArn}\n - undefined\nDescription: Automation Stack for Disable Termination Protection of Instance\nParameters:\n LambdaName: {Description: 'The lambda function name\n\n ', Type: String}\n LambdaRoleArn: {Default: '', Description: 'The ARN of the role that allows Lambda\n created by Automation to perform the action on your behalf\n\n ', Type: String}\nResources:\n LambdaRole:\n Condition: LambdaAssumeRoleNotSpecified\n Properties:\n AssumeRolePolicyDocument:\n Statement:\n - Action: ['sts:AssumeRole']\n Effect: Allow\n Principal:\n Service: [lambda.amazonaws.com]\n Version: '2012-10-17'\n Path: /\n Policies:\n - PolicyDocument:\n Statement:\n Action: ['ec2:ModifyInstanceAttribute']\n Effect: Allow\n Resource: '*'\n Version: '2012-10-17'\n PolicyName: OffProtectInstanceLambdaPolicy\n Type: AWS::IAM::Role\n DisableProtectEC2Lambda:\n Properties:\n Code: {ZipFile: \"import boto3\\n\\n\\ndef handler(event, context):\\n\\tinstance_id\\\n \\ = event[\\\"InstanceId\\\"]\\n\\tec2 = boto3.resource('ec2')\\n\\tinstance = ec2.Instance(instance_id)\\n\\\n \\n\\tinstance.modify_attribute(DisableApiTermination={\\n\\\n \\t\\t'Value': True\\n\\t})\\n\\n\\t# print \\\"\\\n Now eabled\\\"\\n\"}\n FunctionName: {Ref: LambdaName}\n Handler: index.handler\n MemorySize: 128\n Role:\n Fn::If:\n - LambdaAssumeRoleNotSpecified\n - Fn::GetAtt: [LambdaRole, Arn]\n - {Ref: LambdaRoleArn}\n Runtime: python2.7\n Timeout: 60\n Type: AWS::Lambda::Function\n",
  27. "Parameters": [
  28. {
  29. "ParameterValue": "{{LambdaAssumeRole}}",
  30. "ParameterKey": "LambdaRoleArn"
  31. },
  32. {
  33. "ParameterValue": "DisableProtectEC2Lambda-{{automation:EXECUTION_ID}}",
  34. "ParameterKey": "LambdaName"
  35. }
  36. ],
  37. "Capabilities": [
  38. "CAPABILITY_IAM"
  39. ]
  40. },
  41. "name": "createDocumentStack"
  42. },
  43. {
  44. "action": "aws:invokeLambdaFunction",
  45. "inputs": {
  46. "FunctionName": "DisableProtectEC2Lambda-{{automation:EXECUTION_ID}}",
  47. "Payload": "{\"InstanceId\": \"{{InstanceId}}\"}"
  48. },
  49. "name": "DisableProtectionInstance"
  50. },
  51. {
  52. "action": "aws:deleteStack",
  53. "inputs": {
  54. "StackName": "DisableProtectionInstanceStack{{automation:EXECUTION_ID}}"
  55. },
  56. "name": "deleteCloudFormationTemplate"
  57. }
  58. ]
  59. }
Add Comment
Please, Sign In to add comment