MCPcopy Index your code
hub / github.com/zappa/Zappa / update_stack

Method update_stack

zappa/core.py:2791–2899  ·  view source on GitHub ↗

Update or create the CF stack managed by Zappa.

(
        self,
        name,
        working_bucket,
        wait=False,
        update_only=False,
        disable_progress=False,
    )

Source from the content-addressed store, hash-verified

2789 return self.cf_template
2790
2791 def update_stack(
2792 self,
2793 name,
2794 working_bucket,
2795 wait=False,
2796 update_only=False,
2797 disable_progress=False,
2798 ):
2799 """
2800 Update or create the CF stack managed by Zappa.
2801 """
2802 capabilities = []
2803
2804 template = name + "-template-" + str(int(time.time())) + ".json"
2805 with open(template, "wb") as out:
2806 out.write(
2807 bytes(
2808 self.cf_template.to_json(indent=None, separators=(",", ":")),
2809 "utf-8",
2810 )
2811 )
2812
2813 self.upload_to_s3(template, working_bucket, disable_progress=disable_progress)
2814 if self.boto_session.region_name == "us-gov-west-1":
2815 url = "https://s3-us-gov-west-1.amazonaws.com/{0}/{1}".format(working_bucket, template)
2816 else:
2817 url = "https://s3.amazonaws.com/{0}/{1}".format(working_bucket, template)
2818
2819 tags = [{"Key": key, "Value": self.tags[key]} for key in self.tags.keys() if key != "ZappaProject"]
2820 tags.append({"Key": "ZappaProject", "Value": name})
2821 update = True
2822
2823 try:
2824 self.cf_client.describe_stacks(StackName=name)
2825 except botocore.client.ClientError:
2826 update = False
2827
2828 if update_only and not update:
2829 logger.info("CloudFormation stack missing, re-deploy to enable updates")
2830 return
2831
2832 if not update:
2833 self.cf_client.create_stack(StackName=name, Capabilities=capabilities, TemplateURL=url, Tags=tags)
2834 logger.info(f"Waiting for stack {name} to create (this can take a bit)..")
2835 else:
2836 try:
2837 self.cf_client.update_stack(
2838 StackName=name,
2839 Capabilities=capabilities,
2840 TemplateURL=url,
2841 Tags=tags,
2842 )
2843 logger.info(f"Waiting for stack {name} to update..")
2844 except botocore.client.ClientError as e:
2845 if e.response["Error"]["Message"] == "No updates are to be performed.":
2846 wait = False
2847 else:
2848 raise

Callers 2

deployMethod · 0.80
updateMethod · 0.80

Calls 4

upload_to_s3Method · 0.95
remove_from_s3Method · 0.95
updateMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected