I followed this tutorial about getting started with Ruby on Lambda.
Nothing really happened as mentionned in the tutorial because many surprises occurred along the way :)
This tutorial is basically in 3 parts:
- Creating a Hello World example
- Including dependencies
- Migrating a Sinatra application
I had no troubles with the first part. The suprises started from the second.
The main struggles were
- Creating a user
- Create a package
- Deploy
When creating the bucket with the following command
$ aws s3 mb s3://my-bucket
I had this error.
make_bucket failed: s3://my-bucket An error occurred (InvalidAccessKeyId)
when calling the CreateBucket operation: The AWS Access Key Id you
provided does not exist in our records.
First of all, the context is that I had another AWS account and had to setup a second user in my config with the related access key and secret key for this second account.
On one side, in the AWS console, I had to create a user and IAM group for this different account. And no to forget to give this user AdministratorAccess. Then I generated keys for this user.
Then, in bash console, I configured the credentials for this user:
$ aws configure --profile new_user
As explained in the link above, the information to fill in are, as follows:
AWS Access Key ID [None]: EXAMPLE
AWS Secret Access Key [None]: EXAMPLEKEY
Default region name [None]: us-east-1
Default output format [None]: text
๐๐ปThese keys have been generated in the User section, "Create New Access Key"
Then I created the bucket directly in AWS console, in S3. You have to be careful to use the same region as the one you defined for your user.
Then I used the AWS SAM CLI to package your application
$ sam package --template-file template.yaml \
--output-template-file packaged-template.yaml \
--s3-bucket <bucketname>
I had this error:
Unable to upload artifact None referenced by CodeUri parameter
of HelloRubyRecordFunction resource.
An error occurred (InvalidAccessKeyId) when calling the PutObject
operation: The AWS Access Key Id you provided does not exist in our records.
What I had to do to solve this is to pass the profile in the command, as follow:
$ sam package --template-file template.yaml \
--output-template-file packaged-template.yaml \
--s3-bucket <bucketname>
--profile new_user
and it worked ๐๐ป
Successfully packaged artifacts and wrote output template to file
packaged-template.yaml.
Execute the following command to deploy the packaged template
Then I tried to deploy, with the given command:
$ sam deploy --template-file packaged-template.yaml
--stack-name helloRubyRecord
--capabilities CAPABILITY_IAM
An error occurred (InvalidClientTokenId) when calling the DescribeStacks
operation: The security token included in the request is invalid.
Same than before, I had to specify the user in the command:
$ sam deploy --template-file packaged-template.yaml
--stack-name helloRubyRecord
--capabilities CAPABILITY_IAM --profile new_user
Waiting for changeset to be created..
Waiting for stack create/update to complete
Failed to create/update the stack. Run the following command
to fetch the list of events leading up to the failure
aws cloudformation describe-stack-events --stack-name helloRubyRecord
It was better, but I still had an error. This was related to the region
of my bucket. As I mentionned earlier, it has to be the same.
I could learn about this error with the provided command.
$ aws cloudformation describe-stack-events
--stack-name helloRubyRecord
This command gives a big json with events that happened during the deploiement.
I found this error for the "ResourceStatus": "CREATE_FAILED"
"ResourceStatusReason": "Error occurred while GetObject. S3 Error Code:
PermanentRedirect. S3 Error Message: The bucket is in this region: eu-west-3.
Please use this region to retry the request...
So I created a new bucket with a correct region (same than the user has), and tried to deploy again.
aws cloudformation deploy
--template-file packaged-template.yaml
--stack-name HelloRubyRecord
--capabilities CAPABILITY_IAM
--profile new_user
An error occurred (ValidationError) when calling the CreateChangeSet
operation: Stack:arn:aws:cloudformation:eu-west-1:blabla
is in ROLLBACK_COMPLETE state and can not be updated.
I then changed the stack-name
from HelloRubyRecord
to HelloRubyRecord2
.
aws cloudformation deploy
--template-file packaged-template.yaml
--stack-name HelloRubyRecord2
--capabilities CAPABILITY_IAM
--profile new_user
Waiting for changeset to be created..
Waiting for stack create/update to complete
Successfully created/updated stack - HelloRubyRecord2
and it worked ๐๐ป
Here were the main struggles I had to follow the tutorial. I really recommend to do this tuto, just think about these tips if suprises happen.