CloudFormation

 CloudFormation


CloudFormation is a service that helps you model and set up your Amazon Web Services resources so you can spend less time managing those resources and more time focusing on your applications. Here is an example of how to create a CloudFormation stack using the AWS SDK for Python (boto3):

python


import boto3


cloudformation = boto3.client('cloudformation')


stack_name = 'my-stack'


response = cloudformation.create_stack(

    StackName=stack_name,

    TemplateURL='https://my-bucket.s3.amazonaws.com/my-template.yml',

Parameters=[

{

'ParameterKey': 'InstanceType',

'ParameterValue': 't2.micro'

},

{

'ParameterKey': 'KeyName',

'ParameterValue': 'my-key-pair'

}

],

Capabilities=[

'CAPABILITY_IAM'

]

)


print(f"CloudFormation stack {stack_name} created with stack ID {response['StackId']}")



This code creates a CloudFormation stack from a YAML template located in an S3 bucket. The template defines an EC2 instance with a specified instance type and key pair name. The `create_stack` method specifies the stack name, template URL, parameters, and IAM capabilities.


14. DynamoDB

DynamoDB is a fast and flexible NoSQL database service. Here is an example of how to create a DynamoDB table using the AWS SDK for Python (boto3):


```python

import boto3


dynamodb = boto3.resource('dynamodb')


table_name = 'my-table'


table = dynamodb.create_table(

    TableName=table_name,

    KeySchema=[

        {

            'AttributeName': 'id',

            'KeyType': 'HASH'

        }

    ],

    AttributeDefinitions=[        {            'AttributeName': 'id',            'AttributeType': 'S'        }    ],

    ProvisionedThroughput={

        'ReadCapacityUnits': 5,

        'WriteCapacityUnits': 5

    }

)


print(f"DynamoDB table {table_name} created with ARN {table.table_arn}")

This code creates a DynamoDB table with a partition key of id and provisioned throughput of 5 read and write capacity units. The create_table method specifies the table name, key schema, attribute definitions, and provisioned throughput.


No comments:

Post a Comment

The Importance of Cybersecurity in the Digital Age

 The Importance of Cybersecurity in the Digital Age Introduction: In today's digital age, where technology is deeply intertwined with ev...