Giter Club home page Giter Club logo

aws-cloudformation-macros's Introduction

AWS CloudFormation Macros

NOTE that this repository is being archived in favor of similar content located here:

https://github.com/aws-cloudformation/aws-cloudformation-templates/tree/main/aws/services/CloudFormation/MacrosExamples

This repository hosts examples of AWS CloudFormation macros.

Contents

  • Boto3

    The Boto3 macro adds the ability to create CloudFormation resources that represent operations performed by boto3. Each Boto3 resource represents one function call.

  • Count

    The Count macro provides a template-wide Count property for CloudFormation resources. It allows you to specify multiple resources of the same type without having to cut and paste.

  • ExecutionRoleBuilder

    The Execution Role Builder macro provides a more natural syntax for developers to express the permissions they want to attach to IAM execution roles for their applications, while simultaneously providing IAM administrators with a way to templatize those permissions. When used in conjunction with permission boundaries, this provides an effective solution for delegated role creation.

  • Explode

    The Explode macro provides a template-wide Explode property for CloudFormation resources. Similar to the Count macro, it will create multiple copies of a template Resource, but looks up values to inject into each copy in a Mapping.

  • Public-and-Private-Subnet-per-AZ

    This is a Cloudformation Macro used to dynamically add a public and private subnet per Availability Zone when launching a template. When the CreateStack template is launched and a change set is created, the Macro (named 'CreateSubnetsPerAZ') will dynamically add resources to the template for a public and private subnet per available AZ

  • PyPlate

    Run arbitrary python code in your CloudFormation templates

  • S3Objects

    The S3Objects macro adds a new resource type: AWS::S3::Object which you can use to populate an S3 bucket.

  • ShortHand

    The ShortHand macro provides convenience syntax to allow you to create short CloudFormation templates that expand into larger documents upon deployment to a stack.

  • StackMetrics

    When the StackMetrics macro is used in a CloudFormation template, any CloudFormation stack deployed from that template will output custom CloudWatch metrics for the stack.

  • StringFunctions

    Provides string transformation utility functions.

License

This library is licensed under the Apache 2.0 License.

aws-cloudformation-macros's People

Contributors

ericzbeard avatar jpbarto avatar jpeddicord avatar stilvoid avatar technobeats avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aws-cloudformation-macros's Issues

Duplicate repository

Hello,

I open a pull request awslabs/aws-cloudformation-templates/pull/273 because I though that was the "official" repository for Macro Example. However I stumbled upon this repository.

Could you advise as to which repository should be used in order to get a new Cloudformation Macro example included?

Thanks a lot

Update python version for Count macro

The Count macro is setup with python3.6 which is deprecated and it fails to deploy to AWS. Would be great if this macro can be updated with a newer supported version of python 3.9.

$cfn-lint template.yaml 
E2531 Deprecated runtime (python3.6) specified. Updating disabled since 2022-08-17. Please consider updating to python3.9
template.yaml:14:3

S3Objects macro fails PutObject with "the bucket does not allow ACLs"

The S3Objects macro fails to deploy files to a bucket that has ACLs disabled.

steps to repro:

  1. Create a bucket
  2. Disable ACLs on the bucket by setting it to BucketOwnerEnforced.
  3. Use the S3Objects macro to put a file into the bucket.
NewObject:
  Type: AWS::S3::Object
  Properties:
    Target:
      Bucket: !Ref TargetBucket
      Key: README.md
    Body: |
      # My text file
  1. Get the following error on deployment..
[ERROR] ClientError: An error occurred (AccessControlListNotSupported) when calling the
PutObject operation: The bucket does not allow ACLs
Traceback (most recent call last):
  File "/var/task/resource.py", line 72, in handler
    s3_client.put_object(**target)
  File "/var/runtime/botocore/client.py", line 391, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/var/runtime/botocore/client.py", line 719, in _make_api_call
    raise error_class(parsed_response, operation_name)
[ERROR] ClientError: An error occurred (AccessControlListNotSupported) when calling the
PutObject operation: The bucket does not allow ACLs Traceback (most recent call last):
File "/var/task/resource.py", line 72, in handler     s3_client.put_object(**target)   
File "/var/runtime/botocore/client.py", line 391, in _api_call     return self._make_api_call(operation_name, kwargs)   
File "/var/runtime/botocore/client.py", line 719, in _make_api_call     raise error_class(parsed_response, operation_name)

Outputs for Macro Count

Hi , I am wondering how can i get the resource output which created by count macro . For example i need to get the ec2 instance ip which is refered by macro

The S3Objects macro returns "Unrecognized resource types: [AWS::S3::Object]"

There are several issues to get here.

  • The S3Objects macro does not contain a copy of deploy.sh. I copied it from the Count macro, which deployed the functions and the macro resource.
  • the file macro-template has to be renamed to template.yaml for deploy.sh to execute.
  • the resource function needs to be python3.6 not 2.7

Running this template

---
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31

Resources:
  ResourceFunction:
    Type: AWS::Serverless::Function
    Properties:
      Runtime: python3.6
      CodeUri: lambda
      Handler: resource.handler
      Policies: AmazonS3FullAccess

  MacroFunction:
    Type: AWS::Serverless::Function
    Properties:
      Runtime: python3.6
      CodeUri: lambda
      Handler: macro.handler
      Policies: AmazonS3FullAccess
      Environment:
        Variables:
          LAMBDA_ARN: !GetAtt ResourceFunction.Arn

  Macro:
    Type: AWS::CloudFormation::Macro
    Properties:
      Name: S3Objects
      FunctionName: !GetAtt MacroFunction.Arn

results in the error
aws cloudformation create-stack --stack-name bucket
-objects --template-body file://s3bucketa.yaml --capabilities CAPABILITY_AUTO_EXPAND
An error occurred (ValidationError) when calling the CreateStack operation: Template f
ormat error: Unrecognized resource types: [AWS::S3::Object]

I have made the changes in my cloned repo, but I haven't figured that unrecognized resource type yet. If I can figure it out, I will contribute the changes back. Would appreciate any assistance.

Parameterize CloudFormation Count Macro

Hi Team,
We are trying to parameterize the Count value(eg. 2, 3 or any value) by passing the parameter from JSON file to the Cloud formation template. But we are getting error as "Received malformed response from transform". Could you please help us to fix this? if it is possible to parameterize the Count Macro, please share the the steps needs to carried out to fix this issue.

Explode macro fails with "Transform 1234567890::Explode failed without an error message" Error

Issue Description:

If the template contains !Join or a plain list like "files:" property as mentioned below, Explode Transform fails with the error "Transform 1234567890::Explode failed without an error message".

Metadata:

    AWS::CloudFormation::Init:
      config:
        files:
          c:\cfn\cfn-hup.conf:
            content: !Join ['', [
              '[main]
              ',
              stack=, !Ref 'AWS::StackName', '
              ',
              region=, !Ref 'AWS::Region', '
              '
            ]]
          c:\cfn\hooks.d\cfn-auto-reloader.conf:
            content: !Join ['', [
              '[cfn-auto-reloader-hook]
              ',
              'triggers=post.update
              ',
              'path=Resources.LaunchConfiguration1.Metadata.AWS::CloudFormation::Init
              ',
              'action=cfn-init.exe -v -s ', !Ref 'AWS::StackId', ' -r LaunchConfiguration1',' --region ', !Ref 'AWS::Region', '
              '
            ]]
        services:
          windows:
            cfn-hup:
              enabled: 'true'
              ensureRunning: 'true'
              files:
                - c:\cfn\cfn-hup.conf
                - c:\etc\cfn\hooks.d\cfn-auto-reloader.conf

While debugging the issue, I found that this is because when walk_resource function get executed for the above properties, resource.items() here throws below error.

for key, value in resource.items():
AttributeError: 'str' object has no attribute 'items'

Reproduction Steps:

  • Deploy the Explode macro using the stesp mentioned here
  • Create a new CloudFormation stack using the template in Explode_Repro.zip
  • Stack creation will fail with the above error "Transform 1234567890::Explode failed without an error message"

Received malformed response from transform <account-id>:count

If there is % anywhere in CloudFormation template, it gives below error.

Received malformed response from transform 12345XXXXX::Count

For example:

  DiskSpaceAlarm:
    Type: AWS::CloudWatch::Alarm
    Count: !Ref Instancescount
    Properties:
      AlarmDescription: Over 95 of volume space is in use
      AlarmActions:
      - !Ref SNSTopicEc2
      MetricName: "% Free Space"

There should be either some 'delimiter' or lambda should consider only specific (e.g. %d) as a placeholder not all %.

Update python version for Count macro

The Count macro is setup with python3.6 which is deprecated and it fails to deploy to AWS. Would be great if this macro can be updated with a newer supported version of python 3.9.

$cfn-lint template.yaml 
E2531 Deprecated runtime (python3.6) specified. Updating disabled since 2022-08-17. Please consider updating to python3.9
template.yaml:14:3

The String macro does not strip from Right correctly.

There is a bug in the String macro Lambda function when using StripFrom Right.

In this code block

              elif operation == "MaxLength":
                      length = int(event["params"]["Length"])
                      if len(input) <= length:
                          response["fragment"] = input
                      elif "StripFrom" in event["params"]:
                          if event["params"]["StripFrom"] == "Left":
                              response["fragment"] = input[len(input)-length:]
                          elif event["params"]["StripFrom"] != "Right":
                              response["status"] = "failure"
                      else:
                          response["fragment"] = input[:length]

the else is never executed when StripFrom is present to return the result. The transform lambda successfully executes, but since there is no response['fragment'] is the return to CloudFormation, a template processing error results.

If the code is changed to

                elif operation == "MaxLength":
                      length = int(event["params"]["Length"])
                      if len(input) <= length:
                          response["fragment"] = input
                      elif "StripFrom" in event["params"]:
                          if event["params"]["StripFrom"] == "Left":
                              response["fragment"] = input[len(input)-length:]
                          elif event["params"]["StripFrom"] != "Right":
                              response["status"] = "failure"
                         else:
                              response["fragment"] = input[:length]

the the macros return correctly when using StripFrom Right and the response['fragment'] is in the return back to CloudFormation.

Cannot install the Count macro

I've cloned the repo and followed the the steps on README (aka I created an s3 bucket then ran the deploy.sh script.
However I have the following error on the deploy step:

Received malformed response from transform AWS::Serverless-2016-10-31

Am I missing something?

Update python version for boto3 macro

The boto3 macro is setup with python2.7 which is EOL and not even supported by SAM any longer which means it will fail to deploy to AWS. Would be great if this macro can be updated with a newer supported version of python.

AWS CloudFormation Linter................................................Failed

- hook id: cfn-python-lint

- exit code: 2

E2531 Deprecated runtime (python2.7) specified. Updating disabled since 2021-09-30. Please consider updating to python3.8

template.yaml:5:3

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.