sst.dev
sst.dev copied to clipboard
CloudFormation Setup of Backend
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 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.
You can create the cloud formation template using cloudformer as long as you have all the resources created
@SgtPooki Thanks for the tip. We are going to be adding an extra chapter on this soon.
@AcidLeroy How would you create the s3 bucket for serving the site in your yaml?
@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.
@QuantumInformation You might try using cloudformer to figure that out
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 Thanks for posting this here. How do I use the repo? Is it just serverless deploy
?
Wow - this issue is old. Is there any progress on automating the whole setup?
@tcurdt It's now Part II of the guide.https://serverless-stack.com/#part-2
Hmm the entire guide is only for AWS.