logo
down
shadow

How do I add an array of RecordSets into Cloud Formation using troposphere?


How do I add an array of RecordSets into Cloud Formation using troposphere?

By : user2954753
Date : November 22 2020, 10:31 AM
around this issue AliasTarget takes an AliasTarget helper class so you want to do it this way:
code :
from troposphere import GetAtt, Join, Template
from troposphere.route53 import AliasTarget, RecordSetType, RecordSetGroup, RecordSet

t = Template()

myDNSRecord = t.add_resource(RecordSetGroup(
        "devdevopsdemoELBDNSARecord0",
        HostedZoneName=Join("", ["example.net", "."]),
        Comment="DNS Entry to point to the ELB for devopsdemo",
        RecordSets=[
            RecordSet(
                Name="devopsdemo.dev.example.net.",
                Type="A",
                AliasTarget=AliasTarget(
                    GetAtt("devdevopsdemoELB", "CanonicalHostedZoneNameID"),
                    GetAtt("devdevopsdemoELB", "CanonicalHostedZoneName"),
                ),
            ),
            RecordSet(
                Name="devopsdemo-dev.example.net.",
                Type="A",
                AliasTarget=AliasTarget(
                    GetAtt("devdevopsdemoELB", "CanonicalHostedZoneNameID"),
                    GetAtt("devdevopsdemoELB", "CanonicalHostedZoneName"),
                ),
            ),
        ],
    )
)

print t.to_json()


Share : facebook icon twitter icon
Using troposphere for cloud formation, how do I add "propagate at launch" to tags

Using troposphere for cloud formation, how do I add "propagate at launch" to tags


By : user2940224
Date : March 29 2020, 07:55 AM
This might help you ---- UPDATE ---
The feature has been added to the master branch, I just leave my previous answer for reference and in case you don't have access to the latest version of troposphere (ie if you don't clone the repository). You can still use the short function in your code (3rd option), it will work nonetheless.
code :
    asg.Tags = autoscaling.Tags(Name = 'MyTagName', Version = '123456')
    asg.Tags = autoscaling.Tags(Name = 'MyTagName', Version = '123456', 
      NonPropagatedTag=('fail',False))
asg.Tags= [{'Key':'Name','Value':'MyTagName','PropagateAtLaunch':'true'}, 
  {'Key':'Version','Value':'123456','PropagateAtLaunch':'true'}]
asg.Tags= [autoscaling.Tag('Name','MyTagName','true'),
  autoscaling.Tag('Version','123456','true')]
class TagsASG(troposphere.AWSHelperFn):
    defaultPropagateAtLaunch=True
    manyType=[type([]), type(())]

    def __init__(self, **kwargs):
        self.tags = []
        for k, v in sorted(kwargs.iteritems()):
            if type(v) in self.manyType:
              propagate=str(v[1]).lower()
              v=v[0]
            else:
              propagate=str(self.defaultPropagateAtLaunch).lower()
            self.tags.append({
                'Key': k,
                'Value': v,
                'PropagateAtLaunch':propagate,
            })

    def JSONrepr(self):
        return self.tags
    asg.Tags = TagsASG(Name = 'MyTagName', Version = '123456')
    asg.Tags = TagsASG(Name = 'MyTagName', Version = '123456', 
      NonPropagatedTag=('fail',False))
How to pass parameters between one cloud formation to another cloud formation template

How to pass parameters between one cloud formation to another cloud formation template


By : pugnac
Date : March 29 2020, 07:55 AM
wish help you to fix your issue Check out the official documentation for cross-stack references and how it can be used.
The basic idea is that you'll have shared resources put into their own stack so that other stacks can reference those resources. This leads to less copy/paste in all of your cloud formation templates.
Lambda with cloud formation : Pass Cloud formation variable to python code

Lambda with cloud formation : Pass Cloud formation variable to python code


By : Khairuddin Muhammad
Date : March 29 2020, 07:55 AM
To fix this issue You could use the Environment property on your lambda like
code :
LambdaFunction:
  Type: AWS::Lambda::Function
  DependsOn: LambdaRole
  Properties:
    ...
    Environment:
      Variables:
        DESTINATION_BUCKET: !Ref dstBucket
target_bucket = os.environ['DESTINATION_BUCKET']
LambdaFunction:
  Type: AWS::Lambda::Function
  DependsOn: LambdaRole
  Properties:
    Code:
      ZipFile: !Sub |
         ...
            target_bucket     =  "${dstBucket}"
         ...
How to use Fn::If with array values in cloud formation templates

How to use Fn::If with array values in cloud formation templates


By : user2965578
Date : March 29 2020, 07:55 AM
Any of those help Instead of considering value evaluated from Fn::If as a single array item, consider it an array. Replace the Principal with the following and it will work.
JSON
code :
{
  "Principal": {
    "AWS": {
      "Fn::If": [
        "IsProd",
        [
          "arn1"
        ],
        [
          "arn1",
          "arn2"
        ]
      ]
    }
  }
}
Principal:
  AWS:
    Fn::If:
    - IsProd
    - - arn1
    - - arn1
      - arn2
What is best way to create invalidation after cloud formation created cloud front?

What is best way to create invalidation after cloud formation created cloud front?


By : user2982398
Date : March 29 2020, 07:55 AM
I hope this helps you . I use CloudFront with CloudFormation too and I didn' find a way to create invalidation using CloudFormation. If you check AWS Docs, CloudFormation allows 3 types related to CloudFront
code :
CloudFront
  AWS::CloudFront::CloudFrontOriginAccessIdentity
  AWS::CloudFront::Distribution
  AWS::CloudFront::StreamingDistribution
Outputs:
  CloudFrontDistributionID:
    Description: 'CloudFront distribution ID'
    Value: !Ref CloudFrontDistribution
  CloudFrontURL:
    Description: 'CloudFront URL'
    Value:!GetAtt CloudFrontDistribution.DomainName
$ distributionId=${aws cloudformation describe-stacks --stack-name MY_STACK --query "Stacks[0].Outputs[?OutputKey=='CloudFrontDistributionID'].OutputValue" --output text}
$ aws cloudfront create-invalidation --distribution-id $distributionId --paths /index.html /error.html
Related Posts Related Posts :
  • ModuleNotFoundError: No module named 'users'
  • Interpolating with multiple y-values
  • Import warning PACKAGE.egg is added to sys.path
  • Is there a key for the default namespace when creating dictionary for use with xml.etree.ElementTree.findall() in Python
  • Using fill_between() with a Pandas Data Series
  • How to build a lookup table for tri-linear interpolation in NumPy?
  • Matrix vector multiplication along array axes
  • Can a cookiejar object be pickled?
  • __init__.py in project folder breaks nose tests
  • Comparing times with sub-second accuracy
  • advanced search using HayStack + Solr in Django?
  • Base test case class for python unittest
  • The PyData Ecosystem
  • Finding unique entries with oldest time stamp
  • Custom filesize format with Python Humanize?
  • Use `tf.image.resize_image_with_crop_or_pad` to resize numpy array
  • Sum number of occurences of string per row
  • Calculating 'Diagonal Distance' in 3 dimensions for A* path-finding heuristic
  • porting PyGST app to GStreamer1.0 + PyGI
  • Connection refused in Tornado test
  • How much time does take train SVM classifier?
  • Turning a string into list of positive and negative numbers
  • Python lists get specific length of elements from index
  • python.exe version 3.3.2 64 & 32 crash while creating .exe file on win 7 64 & 32 with cx_Freeze
  • Efficient nearest neighbour search for sparse matrices
  • django filter_horizontal can't display
  • How to install FLANN and pyflann on Windows
  • How can I plot the same figure standalone and in a subplot in Matplotlib?
  • read-only cells in ipython notebook
  • filling text file with dates
  • error:AttributeError: 'super' object has no attribute 'db_type' when run "python manage.py syncdb" in django
  • python imblearn make_pipeline TypeError: Last step of Pipeline should implement fit
  • Write to csv: columns are shifted when item in row is empty (Python)
  • DuckDuckGo search returns 'List Index out of range'
  • Python function which can transverse a nested list and print out each element
  • Python installing xlwt module error
  • Python mayavi: Adding points to a 3d scatter plot
  • Making a basic web scraper in Python with only built in libraries - Python
  • How to calculate the angle of the sun above the horizon using pyEphem
  • Fix newlines when writing UTF-8 to Text file in python
  • How to convert backward slash command in python to run on Linux
  • PyCharm Code Inspection doesn't include PEP 8
  • How can I use Python namedtuples to insert rows into mySQL database
  • Increase / Decrease Mac Address in Python from String
  • Scrollable QLabel image in PyQt5
  • (Python 2.7) Access variable from class with accessor/mutator
  • Why does "from [Module] import [Something]" takes more time than "import [Module"
  • jira python oauth: how to get the parameters for authentication?
  • Python - How to specify a relative path by jumping a subdirectory?
  • Extract scientific number from string
  • Scrapy: Python cannot find the spider
  • get the values in a given radius from numpy array
  • Is it possible to duplicate a pipe in Python, so that it has one write end but two read ends?
  • Why does wget use Firefox cookies to login on an authenticated webpage?
  • python import behaviour: different objects from same file?
  • Create YoY Graph with Matplotlib
  • Safe use of eval() or alternatives - python
  • Unix change desktop background seamlessly
  • Profiling Python code that uses multiprocessing?
  • How to query a database after render_template
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org