# Creating EC2 instance directly with serverless

**URL:** https://forum.serverless.com/t/creating-ec2-instance-directly-with-serverless/14877
**Category:** Serverless Architectures
**Tags:** aws
**Created:** [April 29, 2021, 12:52pm UTC](https://forum.serverless.com/t/creating-ec2-instance-directly-with-serverless/14877 "2021-04-29T12:52:40Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![Dleary4395](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/dleary4395/32/4853_2.png) [@Dleary4395](https://forum.serverless.com/u/Dleary4395)
#### Post date: [May 4, 2021, 4:09pm UTC](https://forum.serverless.com/t/creating-ec2-instance-directly-with-serverless/14877/2 "2021-05-04T16:09:57Z")

</div>

You should be able to create EC2 instances via resources. Here’s an example below:

```auto
# serverless.yml

service: usersCrud
provider: aws
functions:

resources: # CloudFormation template syntax
  Resources:
    YourEC2Instance:
      Type: AWS::EC2::Instance
      Properties: 
        ImageId: pickAnImageOrUseYourOwn
        KeyName: yourSshKeyName # This needs to be created manually. CloudFormation does not allow it
        InstanceType: t2.micro // pick whatever size you want
        SubnetId: // your subnetId
        SecurityGroupIds:
          - // your security group IDs

```

You can see the full documentation for all the options available to you here:  
[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-instance.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-instance.html)

Scroll down to the YAML section.

Hope this helps

Edit: Further, this is how you would define any resource that isn’t available to be created with the Serverless framework itself. Resources can be any AWS resource through raw Cloudformation.

---

_[View the full topic](https://forum.serverless.com/t/creating-ec2-instance-directly-with-serverless/14877)._
