How to use firehose_stream_arn method in localstack

Best Python code snippet using localstack_python

__main__.py

Source:__main__.py Github

copy

Full Screen

1import pulumi_aws as aws2import json3from pulumi import ResourceOptions4def main(cluster_name, vpc_id, alb_security_group_name, ingress_cidr_blocks, app_port, load_balancer_name,5 target_group_name, listener_name, role_arn, task_definition_name, cpu, memory, container_port, container_name,6 docker_image, service_name, task_count, health_check_path, alb_subnet_ids, ecs_security_group_name,7 web_acl_association_name, domain_name, hosted_zone_id, certificate_arn, alb_logs_s3_bucket,8 ecs_subnet_ids, aws_region, ecs_log_group_name, environment, firehose_aws_bucket_arn, firehose_stream_name,9 firehose_stream_arn, account_id, ipset_id, waf_rule_name, waf_acl_name, ecs_role_name, ecs_policies_to_create,10 ecs_policies_to_attach):11 """12 Creates an ECS service that runs a specified number of tasks. An ALB sits ontop of of the ECS service. A Route5313 record is created and forwards traffic to the ALB; this component also enables HTTPS. A WAF protects the ALB.14 Security groups are configured as well to ensure proper security throughout the layers of the application.15 The ECS application runs a Docker container and is exposed over the Internet. The compute is managed by Fargate,16 so we don't have to worry about provisioning and managing servers.17 :param cluster_name: name for the ECS cluster to create18 :type cluster_name: str19 :param vpc_id: VPC id20 :type vpc_id: str21 :param alb_security_group_name: name of the security group to create22 :type alb_security_group_name: str23 :param ingress_cidr_blocks: list of IPs that can access the service24 :type ingress_cidr_blocks: list25 :param app_port: port the app will run on26 :type app_port: int27 :param load_balancer_name: name of the load balancer to create28 :type load_balancer_name: str29 :param target_group_name: name of the target group to create30 :type target_group_name: str31 :param listener_name: name of the listener on the load balancer32 :type listener_name: str33 :param role_arn: arn of the ECS task execution role34 :type role_arn: str35 :param task_definition_name: name of the ECS task definition to create36 :type task_definition_name: str37 :param cpu: CPU units38 :type cpu: str39 :param memory: Memory units40 :type memory: str41 :param container_port: port the container runs on42 :type container_port: int43 :param container_name: name of the Docker container44 :type container_name: str45 :param docker_image: name of or link to the Docker image46 :type docker_image: str47 :param service_name: name of the service to create48 :type service_name: str49 :param task_count: number of tasks to run50 :type task_count: int51 :param health_check_path: path to the health check endpoint52 :type health_check_path: str53 :param alb_subnet_ids: list of subnet IDs in which to put the ECS service54 :type alb_subnet_ids: list55 :param ecs_security_group_name: name of the security group for the ECS service56 :type ecs_security_group_name: str57 :param web_acl_association_name: name to give the Web ACL association58 :type web_acl_association_name: str59 :param domain_name: the name of the domain to associate the application to60 :type domain_name: str61 :param hosted_zone_id: ID of the hosted zone to place the Route53 record in62 :type hosted_zone_id: str63 :param certificate_arn: ARN of the SSL certificate to enable HTTPS on the domain_name64 :type certificate_arn: str65 :param alb_logs_s3_bucket: name of the S3 bucket for ALB logs66 :type alb_logs_s3_bucket: str67 :param ecs_subnet_ids: subnets for the ECS tasks68 :type ecs_subnet_ids: list69 :param aws_region: name of the aws region70 :type aws_region: str71 :param ecs_log_group_name: name of the log group72 :type ecs_log_group_name: str73 :param environment: environment variable to set in ECS task74 :type environment: str75 :param firehose_aws_bucket_arn: ARN of the AWS bucket for the Kinesis Firehose stream76 :type firehose_aws_bucket_arn: str77 :param firehose_stream_name: name of the Kinesis Firehose stream78 :type firehose_stream_name: str79 :param firehose_stream_arn: anticipated ARN of the Kinesis Firehose stream80 :type firehose_stream_arn: str81 :param account_id: owning account ID82 :type account_id: str83 :param ipset_id: ID of the IP set to use in the WAF84 :type ipset_id: str85 :param waf_rule_name: name of the WAF86 :type waf_rule_name: str87 :param waf_acl_name: name of the WAF ACL88 :type waf_acl_name: str89 :param ecs_role_name: name of the container role to create90 :type ecs_role_name: str91 :param ecs_policies_to_create: policies to create for the ECS role92 :type ecs_policies_to_create: list of tuples, with the first item in the tuple being the policy name and the second93 being the policy string94 :param ecs_policies_to_attach: ARNs of policies to attach95 :type ecs_policies_to_attach: list96 """97 firehose_role = aws.iam.Role(f"firehoseRole_{environment}", assume_role_policy="""{98 "Version": "2012-10-17",99 "Statement": [100 {101 "Action": "sts:AssumeRole",102 "Principal": {103 "Service": "firehose.amazonaws.com"104 },105 "Effect": "Allow",106 "Sid": ""107 }108 ]109 }110 """)111 firehose_role_policy = aws.iam.RolePolicy(f"{firehose_stream_name}_role_policy",112 role=firehose_role.name,113 policy=f"""{{114 "Version": "2012-10-17",115 "Statement": [116 {{117 "Sid": "",118 "Effect": "Allow",119 "Action": [120 "glue:GetTable",121 "glue:GetTableVersion",122 "glue:GetTableVersions"123 ],124 "Resource": [125 "arn:aws:glue:us-west-2:{account_id}:catalog",126 "arn:aws:glue:us-west-2:{account_id}:database/%FIREHOSE_POLICY_TEMPLATE_PLACEHOLDER%",127 "arn:aws:glue:us-west-2:{account_id}:table/%FIREHOSE_POLICY_TEMPLATE_PLACEHOLDER%/%FIREHOSE_POLICY_TEMPLATE_PLACEHOLDER%"128 ]129 }},130 {{131 "Sid": "",132 "Effect": "Allow",133 "Action": [134 "s3:AbortMultipartUpload",135 "s3:GetBucketLocation",136 "s3:GetObject",137 "s3:ListBucket",138 "s3:ListBucketMultipartUploads",139 "s3:PutObject"140 ],141 "Resource": [142 "{firehose_aws_bucket_arn}",143 "{firehose_aws_bucket_arn}/*"144 ]145 }},146 {{147 "Sid": "",148 "Effect": "Allow",149 "Action": [150 "lambda:InvokeFunction",151 "lambda:GetFunctionConfiguration"152 ],153 "Resource": "arn:aws:lambda:us-west-2:{account_id}:function:%FIREHOSE_POLICY_TEMPLATE_PLACEHOLDER%"154 }},155 {{156 "Effect": "Allow",157 "Action": [158 "kms:GenerateDataKey",159 "kms:Decrypt"160 ],161 "Resource": [162 "arn:aws:kms:us-west-2:{account_id}:key/%FIREHOSE_POLICY_TEMPLATE_PLACEHOLDER%"163 ],164 "Condition": {{165 "StringEquals": {{166 "kms:ViaService": "s3.us-west-2.amazonaws.com"167 }},168 "StringLike": {{169 "kms:EncryptionContext:aws:s3:arn": [170 "arn:aws:s3:::%FIREHOSE_POLICY_TEMPLATE_PLACEHOLDER%/*"171 ]172 }}173 }}174 }},175 {{176 "Sid": "",177 "Effect": "Allow",178 "Action": [179 "logs:PutLogEvents"180 ],181 "Resource": [182 "arn:aws:logs:us-west-2:{account_id}:log-group:/aws/kinesisfirehose/{firehose_stream_name}:log-stream:*"183 ]184 }},185 {{186 "Sid": "",187 "Effect": "Allow",188 "Action": [189 "kinesis:DescribeStream",190 "kinesis:GetShardIterator",191 "kinesis:GetRecords",192 "kinesis:ListShards"193 ],194 "Resource": "arn:aws:kinesis:us-west-2:{account_id}:stream/%FIREHOSE_POLICY_TEMPLATE_PLACEHOLDER%"195 }},196 {{197 "Effect": "Allow",198 "Action": [199 "kms:Decrypt"200 ],201 "Resource": [202 "arn:aws:kms:us-west-2:{account_id}:key/%FIREHOSE_POLICY_TEMPLATE_PLACEHOLDER%"203 ],204 "Condition": {{205 "StringEquals": {{206 "kms:ViaService": "kinesis.us-west-2.amazonaws.com"207 }},208 "StringLike": {{209 "kms:EncryptionContext:aws:kinesis:arn": "arn:aws:kinesis:us-west-2:{account_id}:stream/%FIREHOSE_POLICY_TEMPLATE_PLACEHOLDER%"210 }}211 }}212 }}213 ]214 }}"""215 )216 firehose_stream = aws.kinesis.FirehoseDeliveryStream(firehose_stream_name,217 destination="s3",218 s3_configuration=219 aws.kinesis.FirehoseDeliveryStreamS3ConfigurationArgs(220 role_arn=firehose_role.arn,221 bucket_arn=firehose_aws_bucket_arn,222 buffer_size=1,223 buffer_interval=60,224 ))225 wafrule = aws.wafregional.Rule(waf_rule_name,226 name=waf_rule_name,227 metric_name=waf_rule_name,228 predicates=[aws.wafregional.RulePredicateArgs(229 data_id=ipset_id,230 negated=False,231 type="IPMatch",232 )])233 webacl = aws.wafregional.WebAcl(waf_acl_name,234 name=waf_acl_name,235 metric_name=waf_acl_name,236 default_action=aws.wafregional.WebAclDefaultActionArgs(237 type="BLOCK",238 ),239 rules=[aws.wafregional.WebAclRuleArgs(240 action=aws.wafregional.WebAclRuleActionArgs(241 type="ALLOW",242 ),243 priority=1,244 rule_id=wafrule.id,245 type="REGULAR",246 )],247 logging_configuration=aws.wafregional.WebAclLoggingConfigurationArgs(248 log_destination=aws.get_arn(arn=firehose_stream_arn).arn249 ),250 opts=ResourceOptions(depends_on=[firehose_stream, wafrule])251 )252 ecs_role = aws.iam.Role(253 ecs_role_name,254 name=ecs_role_name,255 assume_role_policy="""{256 "Version": "2012-10-17",257 "Statement": [258 {259 "Action": "sts:AssumeRole",260 "Principal": {261 "Service": "ecs-tasks.amazonaws.com"262 },263 "Effect": "Allow",264 "Sid": ""265 }266 ]267 }268 """269 )270 policy_arns = []271 for policy in ecs_policies_to_create:272 iam_policy = aws.iam.Policy(273 policy[0],274 name=policy[0],275 policy=policy[1]276 )277 policy_arns.append(iam_policy.arn)278 for index, policy_arn in enumerate(policy_arns + ecs_policies_to_attach):279 attach = aws.iam.RolePolicyAttachment(280 f'attached_{index}_{environment}',281 role=ecs_role.name,282 policy_arn=policy_arn283 )284 ecs_cluster = aws.ecs.Cluster(cluster_name, name=cluster_name)285 alb_security_group = aws.ec2.SecurityGroup(alb_security_group_name,286 name=alb_security_group_name,287 vpc_id=vpc_id,288 description='Enable HTTPS access',289 ingress=[aws.ec2.SecurityGroupIngressArgs(290 protocol='tcp',291 from_port=app_port,292 to_port=app_port,293 cidr_blocks=ingress_cidr_blocks294 )],295 egress=[aws.ec2.SecurityGroupEgressArgs(296 protocol='-1',297 from_port=0,298 to_port=0,299 cidr_blocks=['0.0.0.0/0'],300 )],301 )302 ecs_security_group = aws.ec2.SecurityGroup(ecs_security_group_name,303 name=ecs_security_group_name,304 vpc_id=vpc_id,305 description='Enable ALB Access',306 ingress=[307 aws.ec2.SecurityGroupIngressArgs(308 protocol='tcp',309 from_port=container_port,310 to_port=container_port,311 security_groups=[alb_security_group.id]312 )313 ],314 egress=[aws.ec2.SecurityGroupEgressArgs(315 protocol='-1',316 from_port=0,317 to_port=0,318 cidr_blocks=['0.0.0.0/0'],319 )],320 )321 load_balancer = aws.lb.LoadBalancer(load_balancer_name,322 name=load_balancer_name,323 security_groups=[alb_security_group.id],324 subnets=alb_subnet_ids,325 access_logs=aws.lb.LoadBalancerAccessLogsArgs(326 bucket=alb_logs_s3_bucket,327 prefix='alb-logs',328 enabled=True,329 ),330 )331 target_group = aws.lb.TargetGroup(target_group_name,332 name=target_group_name,333 port=container_port,334 protocol='HTTPS',335 target_type='ip',336 vpc_id=vpc_id,337 health_check={338 "path": f"{health_check_path}",339 "port": f"{container_port}",340 "protocol": "HTTPS"341 }342 )343 listener = aws.lb.Listener(listener_name,344 load_balancer_arn=load_balancer.arn,345 port=app_port,346 protocol='HTTPS',347 certificate_arn=certificate_arn,348 default_actions=[aws.lb.ListenerDefaultActionArgs(349 type='forward',350 target_group_arn=target_group.arn,351 )],352 )353 web_acl_association = aws.wafregional.WebAclAssociation(web_acl_association_name,354 resource_arn=load_balancer.arn,355 web_acl_id=webacl.id)356 route_53_record = aws.route53.Record(domain_name,357 zone_id=hosted_zone_id,358 name=domain_name,359 type="A",360 aliases=[aws.route53.RecordAliasArgs(361 name=load_balancer.dns_name,362 zone_id=load_balancer.zone_id,363 evaluate_target_health=False,364 )]365 )366 ecs_log_group = aws.cloudwatch.LogGroup(f'ecs/{ecs_log_group_name}', name=f'ecs/{ecs_log_group_name}')367 task_definition = aws.ecs.TaskDefinition(task_definition_name,368 family=task_definition_name,369 cpu=cpu,370 memory=memory,371 network_mode='awsvpc',372 requires_compatibilities=['FARGATE'],373 execution_role_arn=role_arn,374 task_role_arn=ecs_role.arn,375 container_definitions=json.dumps([{376 'name': container_name,377 'image': docker_image,378 'portMappings': [{379 'containerPort': container_port,380 'protocol': 'tcp'381 }],382 "environment": [383 {384 "name": "ENVIRONMENT",385 "value": f"{environment}"386 }387 ],388 "logConfiguration": {389 "logDriver": "awslogs",390 "options": {391 "awslogs-group": f'ecs/{ecs_log_group_name}',392 "awslogs-region": aws_region,393 "awslogs-stream-prefix": "container-"394 }395 }396 }])397 )398 ecs_service = aws.ecs.Service(service_name,399 cluster=ecs_cluster.arn,400 desired_count=task_count,401 launch_type='FARGATE',402 task_definition=task_definition.arn,403 network_configuration=aws.ecs.ServiceNetworkConfigurationArgs(404 assign_public_ip=False,405 subnets=ecs_subnet_ids,406 security_groups=[ecs_security_group.id],407 ),408 load_balancers=[aws.ecs.ServiceLoadBalancerArgs(409 target_group_arn=target_group.arn,410 container_name=container_name,411 container_port=container_port,412 )],413 opts=ResourceOptions(depends_on=[listener]),...

Full Screen

Full Screen

firehose_api.py

Source:firehose_api.py Github

copy

Full Screen

...68 stream = {69 'HasMoreDestinations': False,70 'VersionId': '1',71 'CreateTimestamp': time.time(),72 'DeliveryStreamARN': firehose_stream_arn(stream_name),73 'DeliveryStreamStatus': 'ACTIVE',74 'DeliveryStreamName': stream_name,75 'Destinations': []76 }77 DELIVERY_STREAMS[stream_name] = stream78 if s3_destination:79 update_destination(stream_name=stream_name, destination_id=short_uid(), s3_update=s3_destination)80 return stream81def delete_stream(stream_name):82 stream = DELIVERY_STREAMS.pop(stream_name, {})83 if not stream:84 return error_not_found(stream_name)85 return {}86def get_stream(stream_name):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful