How to create a Lambda in CloudFormation
You can create a Lambda in CloudFormation as follows: Option 1 - Inline code Resources: MyLambdaFunction: Type: AWS::Lambda::Function Properties: FunctionName: MyLambdaFunction Runtime: python3.8 Handler: index.lambda_handler Code: ZipFile: | import json def lambda_handler(event, context): # Your Lambda function code here return { 'statusCode': 200, 'body': json.dumps('Hello from Lambda!') } Role: !GetAtt MyLambdaExecutionRole.Arn In this example, instead of specifying the S3Bucket and S3Key properties under the Code section, you use the ZipFile property to provide the actual code as a multiline string....
How to create a Lambda in Terraform
To create an AWS Lambda function using Terraform, you need to define the necessary resources in a Terraform configuration file. Here鈥檚 an example of how you can create a Lambda function using Terraform: Option 1 - Seperate Lambda Source Create a new directory for your Terraform configuration and navigate to it in your terminal. Create a new file with a .tf extension, such as lambda.tf, and open it in a text editor....
How to create a Bastion server in Terraform
To create a Bastion server using Terraform, you need to define the necessary resources in a Terraform configuration file. Here鈥檚 an example of how you can create a Bastion server using Terraform: # Define the security group resource "aws_security_group" "bastion_sg" { name = "bastion-security-group" description = "Bastion Security Group" ingress { from_port = 22 to_port = 22 protocol = "tcp" cidr_blocks = ["0.0.0.0/0"] } vpc_id = "your-vpc-id" } # Define the Bastion instance resource "aws_instance" "bastion_instance" { ami = "your-ami-id" instance_type = "t2....
How to create a Bastion server in CloudFormation
To create a Bastion server using AWS CloudFormation, you need to define the necessary resources in a CloudFormation template. Here鈥檚 an example of how you can create a Bastion server using CloudFormation: AWSTemplateFormatVersion: "2010-09-09" Resources: BastionSecurityGroup: Type: AWS::EC2::SecurityGroup Properties: GroupDescription: Bastion Security Group SecurityGroupIngress: - IpProtocol: tcp FromPort: 22 ToPort: 22 CidrIp: 0.0.0.0/0 VpcId: "your-vpc-id" BastionInstance: Type: AWS::EC2::Instance Properties: ImageId: "your-ami-id" InstanceType: "t2.micro" # Update with the desired instance type SecurityGroupIds: - !...
How to you create a Cross Account Role in Terraform
To create a cross-account role in Terraform, you need to perform the following steps: 1. Define the IAM role Define the IAM role in the Terraform configuration resource "aws_iam_role" "cross_account_role" { name = "CrossAccountRole" assume_role_policy = <<EOF { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::<ACCOUNT_ID>:root" }, "Action": "sts:AssumeRole" } ] } EOF } In the assume_role_policy section, replace <ACCOUNT_ID> with the AWS account ID of the target account that will assume this role....
How to you create a Cross Account Role in CloudFormation
To create a cross-account role in CloudFormation, you can follow these steps: 1. Create a CloudFormation template Create a new CloudFormation template in YAML or JSON format. This template will define the resources, including the cross-account role, that you want to create. 2. Define the cross-account role Within your CloudFormation template, define the cross-account role using the AWS::IAM::Role resource type. Specify the necessary properties such as RoleName, AssumeRolePolicyDocument, and ManagedPolicyArns....
How to create Public and Private Subnets in CloudFormation
To create public and private subnets in AWS CloudFormation, you can use the AWS CloudFormation Template Language (CFT) to define your network configuration. Here鈥檚 an example CloudFormation template that demonstrates how to create public and private subnets within a Virtual Private Cloud (VPC) in AWS: Resources: MyVPC: Type: AWS::EC2::VPC Properties: CidrBlock: 10.0.0.0/16 Tags: - Key: Name Value: my-vpc PublicSubnet: Type: AWS::EC2::Subnet Properties: VpcId: !Ref MyVPC CidrBlock: 10.0.0.0/24 AvailabilityZone: us-west-2a Tags: - Key: Name Value: public-subnet PrivateSubnet: Type: AWS::EC2::Subnet Properties: VpcId: !...
How to create Public and Private Subnets in Terraform
To create public and private subnets in Terraform, you can use the AWS provider to define your network configuration. Here鈥檚 an example configuration that demonstrates how to create public and private subnets within a Virtual Private Cloud (VPC) in AWS: # Define your AWS provider configuration provider "aws" { region = "us-west-2" # Update with your desired region } # Create the VPC resource "aws_vpc" "my_vpc" { cidr_block = "10.0.0.0/16" # Update with your desired VPC CIDR block tags = { Name = "my-vpc" } } # Create the public subnet resource "aws_subnet" "public_subnet" { vpc_id = aws_vpc....
How to create an Internet Gateway and assign it to an EC2 in CloudFormation
To create an Internet Gateway and associate it with an EC2 instance using AWS CloudFormation, you can follow these steps: Step 1: Create a CloudFormation template Create a new YAML or JSON file with a .yaml or .json extension (e.g., template.yaml), and add the following contents: AWSTemplateFormatVersion: "2010-09-09" Resources: MyVPC: Type: AWS::EC2::VPC Properties: CidrBlock: 10.0.0.0/16 # Replace with your desired VPC CIDR block MyInternetGateway: Type: AWS::EC2::InternetGateway MyVPCGatewayAttachment: Type: AWS::EC2::VPCGatewayAttachment Properties: VpcId: !...
How to create an Internet Gateway and assign it to an EC2 in Terraform
To create an Internet gateway and assign it to an EC2 instance using Terraform, you can follow these steps: Step 1: Set up your Terraform environment Install Terraform: Download and install Terraform from the official website (https://www.terraform.io/downloads.html) based on your operating system. Configure AWS credentials: Set up your AWS access key and secret access key as environment variables or use an AWS profile configured on your system. Step 2: Create a Terraform configuration file Create a new file with a ....