AWS Amplify Removes Lambda Post Confirmation Function Upon Deploying Updates In The CLI - aws-amplify

Problem:
When updating AWS Amplify via the CLI, with amplify push -y, I notice the congito Lambda Triggers are temporarily removed.
How do I sustain the triggers whilst updating the environment? Is this normal behaviour?

Related

How do Firebase functions handle PubSub topics created with Google Cloud?

I found a two sources that indirectly reference the fact that when creating Google Cloud PubSub subscriptions with Firebase (using the firebase-functions/v1 npm package), Firebase automatically creates the PubSub Topics and PubSub subscriptions:
Cap your Firebase spending #1: Setting up a billing PubSub topic (YouTube)
Firebase PubSub Trigger with Message Ordering (StackOverflow)
As a result, you do not need to (for example) use $ gcloud pubsub topics create $TOPIC_NAME and $ gcloud pubsub subscriptions create $SUBSCRIPTION_NAME to create the topic and subscriptions.
Is this behavior actually documented anywhere?
I would like to create my PubSub subscriptions outside of Firebase. This enables me to create subscriptions using the "dead letter topic" feature and enables me to consistently document my Topics and Subscriptions within my larger Google Cloud Project.
Is it possible to deploy cloud functions within my Firebase project that listen to subscriptions created outside of Firebase?
For example, could I deploy Firebase cloud functions that use the #google-cloud/pubsub npm package instead of firebase-functions/v1?
Firebase automatically creates the PubSub Topics and PubSub subscriptions as you can see that in the process & code described in public docs.
And It is possible to deploy cloud functions within Firebase projects that listen to subscriptions created outside of Firebase. If you want to deploy cloud function which handles dead-letter-topics in firebase you have to follow these steps:
Create a pubsub topic using gcloud command "gcloud pubsub topics
create"
Create a firebase function with trigger pointing to the
topic created in step 1
Deploy the function using firebase
command "firebase deploy --only functions"
Update the subscription
created and enable dead letter feature. This could also be done
using the gcloud command
Make necessary updates to the firebase
function and redeploy the function using firebase deploy --only functions
Reason behind updating subscription is, When deploying the function using the firebase cli, the subscription may be recreated with standard retry settings and results in disabling dead-letter-topic.
So After each function deployment, you need to update the subscription accordingly.
You can use postdeploy hooks in firebase cli through which you can re-enable the dead-letter settings post a deployment automatically. Please see the below steps for the same:
Create a postdeploy.sh script that contains the gcloud command to update a subscription as below. Please see below as just an example and should be modified for variables. Command details are available here
gcloud pubsub subscriptions update projects/$GCLOUD_PROJECT/subscriptions/$SUBSCRIPTION_NAME --dead-letter-topic=$TOPICNAME --max-delivery-attempts=5
Reference the above postdeploy.sh in firebase.json file as a post hook. Example below:
{
"functions": {
"postdeploy": "./postdeploy.sh",
"source": "functions"
}
}
Deploy the firebase function using regular firebase command firebase deploy --only functions:XYZ
For other alternatives go through this Article.
And you can deploy firebase functions which uses the #google-cloud/pubsub

What causes typescript compile error when deploying

I roughly following this tutorial to make a cloud function with typescript. It works fine in development, but when I try to deploy it (firebase deploy --only functions), I get A LOT of typescript errors. I have no idea why. It works in dev, why can't I push the same set up to Firebase?
Follow the below steps for a successful cloud functions deployment:
After you have created a Firebase project using this step, install
the Firebase CLI using : npm install -g firebase-tools.
Run firebase login to log in via the browser and authenticate the
firebase tool.
Run firebase init firestore
Run firebase init functions
When you run firebase init functions, there will be prompts, 1st
prompt : “What language would you like to use to write Cloud
Functions?” -> Choose Typescript. 2nd prompt : Do you want to use
ESlint to catch probable bugs and enforce style (y/n)? -> Choose n.
By selecting no you will be saving yourself from the typescript
compile errors.
Once initialization is complete, uncomment the sample in index.ts and
run npm run serve to see a "Hello World" function in action. Once you
can see the output in Firebase emulator, you will know the functions
executed properly.
Now, before you deploy the functions, assign the Cloud Functions
Invoker, Cloud Functions Admin and Cloud Functions Developer role to
project-id#appspot.gserviceaccount.com
Now run firebase deploy –only functions. The deployment will be
successful but the browser might show 403 errors ( Client does not
have permission..) For that, select your cloud function (check box)
click "Add members" under the Permissions tab in the right side,
enter "allUsers" under "New members", select Role as Cloud Functions -> Cloud Functions Invoker and then save the configuration.
If you do not want to give public access to your cloud functions, you
can set up authentication, by skipping the previous step. In Cloud
Shell, run gcloud auth print-identity-token. This outputs a token
which you will be authenticating your cloud function with. Now
provide authentication credentials in your request as a
Google-generated ID token stored in an Authorization header with this
command :
curl https://REGION-PROJECT_ID.cloudfunctions.net/FUNCTION_NAME \ -H "Authorization: bearer $(gcloud auth print-identity-token)"

I created an Amplify App via the console but I am unable to pull it

I created a Reactjs NextJS app in the Amplify console, and I am trying to pull it. I did have some problems initially because I am using AWS SSO to sign in, but after using aws-export-credentials I was able to get around that exporting credentials to a new profile, not sure if that has anything to do with it.
My app is having a front-end only, but when I try to pull it, it complains that no backend exists.
Cannot find any backend environment in the Amplify Console App next-app.
Failed to pull the backend.
Cannot find any backend environment in the Amplify Console App next-app.
Error: Cannot find any backend environment in the Amplify Console App next-app.
at getBackendEnv (/usr/local/lib/node_modules/#aws-amplify/cli/node_modules/amplify-provider-awscloudformation/src/attach-backend.js:297:14)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at Object.run (/usr/local/lib/node_modules/#aws-amplify/cli/node_modules/amplify-provider-awscloudformation/src/attach-backend.js:76:22)
at Object.attachBackend (/usr/local/lib/node_modules/#aws-amplify/cli/node_modules/amplify-provider-awscloudformation/src/index.ts:50:3)
at Object.queryProvider (/usr/local/lib/node_modules/#aws-amplify/cli/src/attach-backend-steps/a10-queryProvider.ts:12:3)
at Object.attachBackend (/usr/local/lib/node_modules/#aws-amplify/cli/src/attach-backend.ts:20:5)
at Object.run (/usr/local/lib/node_modules/#aws-amplify/cli/src/commands/pull.ts:59:5)
at Object.executeAmplifyCommand (/usr/local/lib/node_modules/#aws-amplify/cli/src/index.ts:373:5)
at executePluginModuleCommand (/usr/local/lib/node_modules/#aws-amplify/cli/src/execution-manager.ts:178:3)
at Object.executeCommand (/usr/local/lib/node_modules/#aws-amplify/cli/src/execution-manager.ts:30:5)
at Object.run (/usr/local/lib/node_modules/#aws-amplify/cli/src/index.ts:205:5)
I will otherwise make the app from the cli instead but still wanting to understand why this has happened.

How do I start AWS Codepipeline from client?

I had built an AWS CDK code pipeline that triggers build on every git commit, but I want to trigger the build throw client function can anyone please guide me on how can I trigger the start-pipeline function throw the client-side.
You can use the AWS CLI to start the pipeline manually, the same thing is possible via a API call.
From: Start a pipeline manually
aws codepipeline start-pipeline-execution --name MyFirstPipeline
Alternatively you can add a review button within CodePipeline.
From: Manage approval actions in CodePipeline
In AWS CodePipeline, you can add an approval action to a stage in a
pipeline at the point where you want the pipeline execution to stop so
that someone with the required AWS Identity and Access Management
permissions can approve or reject the action.

Prevent firestore triggers when serving firebase functions locally

I am new to Firebase, I setup a project and using nodejs + nestjs
I have a https trigger function that adds record to Firestore
I have a Firestore document onCreate trigger, to duplicate data to another collection
Then I try to run Firebase locally by running npm run serve which is calling firebase serve --only functions
Then I can access the https function via postman app.
First problem is Firestore onCreate trigger is not fired locally when I call my local https function.
Second problem is Firestore onCreate trigger is run on server and I can see running logs, which means in development time, some buggy bad code could be running on server and that code might corrupt data (while the good code is under development and bugs are fixing on my local)
So my question is, how usually people do development on their local and testing?
firebase serve --only functions only emulates HTTPS functions.
firebase experimental:functions:shell works with everything else, but you have to construct stub data to send to it.
See the documentation for more information:
Run Functions Locally
Unit testing functions

Resources