Advertisement
Guest User

Untitled

a guest
Feb 27th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. #!/bin/bash
  2. #This script requires an up-to-date version of the aws cli tool
  3.  
  4. profile=$1
  5. environment=$2
  6.  
  7. region=us-east-1
  8. service_name=com.amazonaws.$region.s3
  9.  
  10. get_env_vpc_id () {
  11. local profile=$1
  12. local env=$2
  13. local vpc_id
  14. vpc_id=$(aws --profile $profile ec2 describe-vpcs \
  15. --filters "Name=tag:Name,Values=$env" \
  16. --query 'Vpcs[].VpcId|[0]' \
  17. --output text)
  18. echo $vpc_id
  19. }
  20.  
  21. get_vpc_route_table_ids () {
  22. local profile=$1
  23. local vpc=$2
  24. local routetable_id
  25. routetable_id=$(aws --profile $profile ec2 \
  26. describe-route-tables \
  27. --filters "Name=vpc-id,Values=$vpc" \
  28. --query '*[][].RouteTableId' --output text | tr '[:blank:]' ',')
  29. echo $routetable_id
  30. }
  31.  
  32. create_vpc_end_point () {
  33. local profile=$1
  34. local vpc_id=$2
  35. local service_name=$3
  36. local route_table_ids
  37. route_table_ids=$(echo $4 | tr ',' ' ')
  38. aws --profile $profile ec2 create-vpc-endpoint \
  39. --vpc-id $vpc_id \
  40. --service-name $service_name \
  41. --route-table-ids $route_table_ids
  42. }
  43.  
  44. create_security_group () {
  45. local profile=$1
  46. local vpc_id=$2
  47. local prefix_list_id
  48. prefix_list_id=$(aws ec2 describe-prefix-lists \
  49. --query 'PrefixLists[0].PrefixListId' \
  50. --output text)
  51. aws ec2 create-security-group \
  52. --group-name my-lambda \
  53. --description 'Lambda Access to S3' --vpc-id $vpc_id
  54. }
  55.  
  56. vpc_id=$(get_env_vpc_id $profile $environment)
  57. route_table_ids=$(get_vpc_route_table_ids $profile $vpc_id)
  58. create_vpc_end_point $profile $vpc_id $service_name $route_table_ids
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement