sst.dev icon indicating copy to clipboard operation
sst.dev copied to clipboard

CloudFormation Setup of Backend

Open AcidLeroy opened this issue 7 years ago • 12 comments

For this tutorial I think it is great that you walk through creating the all the resources by hand so you can describe why you are doing it. But I also think as an additional chapter it may be worth putting a YAML file together describing the system using cloud formation templates. This makes deleting and creating the app a lot easier. I'm curious if anyone else has attempted to do this? I've been attempting to create the necessary template as I read along, but I got a bit stuck at the new identity pool portion. It's not clear to me how to properly setup the cloudformation template for this part of the resource creation. Here is what I have:

resources:
  Resources:
    ScratchAppDB:
      Type: AWS::DynamoDB::Table
      Properties:
        TableName: notes_serverless
        AttributeDefinitions:
          - AttributeName: userId
            AttributeType: S
          - AttributeName: noteId
            AttributeType: S
        KeySchema:
          - AttributeName: userId
            KeyType: HASH
          - AttributeName: noteId
            KeyType: RANGE
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
    
    ScratchAppS3Bucket:
      Type: AWS::S3::Bucket
      Properties:
        BucketName: scratchbucket505
        CorsConfiguration:
          CorsRules:
            - AllowedHeaders: ['*']
              AllowedMethods: [GET, PUT, POST, HEAD]
              AllowedOrigins: ['*']
              MaxAge: '3000'

    ScratchUserPool:
      Type: AWS::Cognito::UserPool
      Properties:
        UserPoolName: notes-user-pool

    ScratchUserPoolClient:
      Type: AWS::Cognito::UserPoolClient
      Properties:
        ClientName: notes-client
        ExplicitAuthFlows: [ADMIN_NO_SRP_AUTH]
        UserPoolId:
          Ref: ScratchUserPool

    ScratchIdentityPool: # <------------------------THIS IS BROKEN
      Type: AWS::Cognito::IdentityPool
      Properties:
        IdentityPoolName: ScratchIdentityPool
        AllowUnauthenticatedIdentities: false
        CognitoIdentityProviders:
          - ClientId:
              Ref: ScratchUserPoolClient
            ProviderName:
              Ref: ScratchUserPool

AcidLeroy avatar Jul 11 '17 13:07 AcidLeroy

@AcidLeroy Yeah a couple of our readers have looked into this. Here is a thread on this that might help you - http://forum.serverless.com/t/cognito-user-identity-pools-as-serverless-yml-resource-defs/2050/9.

Adding this as an extra chapter is a good idea. We'll definitely look into it.

In the time being we do have one piece of advice on this. It might be a personal preference thing but we prefer keeping the CloudFormation stack that creates the other parts of your infrastructure (Dynamo, Cognito, etc) separate from the Lambda and API Gateway one. It's just a lot safer to deal with rollbacks and errors and it makes re-deploying your Lambdas quicker.

jayair avatar Jul 11 '17 17:07 jayair

You can create the cloud formation template using cloudformer as long as you have all the resources created

SgtPooki avatar Aug 23 '17 07:08 SgtPooki

@SgtPooki Thanks for the tip. We are going to be adding an extra chapter on this soon.

jayair avatar Aug 23 '17 16:08 jayair

@AcidLeroy How would you create the s3 bucket for serving the site in your yaml?

quantuminformation avatar Oct 06 '17 13:10 quantuminformation

@QuantumInformation Just noticed your comment. This section that @AcidLeroy has is only for the backend and is created when you run serverless deploy. You could add the React part here as well but it might be better to have that in a separate stack, just to separate things.

jayair avatar Oct 22 '17 00:10 jayair

@QuantumInformation You might try using cloudformer to figure that out

bharloe avatar Oct 22 '17 00:10 bharloe

Hey guys, I've made an attempt to automate the API creation with cloudFormation with the help of a bash script and a configuration file. Unfortunately at this point CloudFormation still does not support email as User Pool username.

Here is my forked repo https://github.com/timoteoalvarenga/serverless-stack-demo-api

timoteoalvarenga avatar Nov 13 '17 19:11 timoteoalvarenga

@timoteoalvarenga Thanks for posting this here. How do I use the repo? Is it just serverless deploy?

jayair avatar Nov 14 '17 19:11 jayair

Wow - this issue is old. Is there any progress on automating the whole setup?

tcurdt avatar May 29 '19 19:05 tcurdt

@tcurdt It's now Part II of the guide.https://serverless-stack.com/#part-2

jayair avatar May 30 '19 18:05 jayair

@jayair Ah, nice. I didn't see that yet.

But it's only AWS and not for Google?

tcurdt avatar May 30 '19 18:05 tcurdt

Hmm the entire guide is only for AWS.

jayair avatar Jun 01 '19 00:06 jayair