I'm playing with AWS Amplify since I've to introduce some of its feature in a legacy application that has no framework (no React, no Angular: just vanilla JS).
I used successfully the Auth module so I recreated a simple sign up/in/out strategy. What I want now is to call a REST API, using REST API module. So I created an API using API Gateway PetStore example and I would interact with it.
So I created the configuration:
import Amplify from '#aws-amplify/core';
Amplify.configure({
Auth: {
...
},
API: {
endpoints: [
{
name: "PetStore", // name of the API in API Gateway console
endpoint: "https://XXX.execute-api.eu-central-1.amazonaws.com/dev",
region: "eu-central-1",
paths: ['/']
}
]
}
});
and somewhere else:
import Api from '#aws-amplify/api-rest';
Api.get('PetStore', '/pets', {})
.then(response => {
console.log(response)
}).catch(error => {
console.log(error);
});
But, when executed, I get always the same error:
API PetStore does not exist
Any idea? Remember that:
API Already exist
I don't want to use Amplify CLI to create AWS resources
I'd like to add that #Deiv was correct to suggest API.configure(), this worked for me. After trying amplify pull and amplify push I still received the error API <api-name> does not exist.
So my code now looks like this:
import Amplify, { API } from 'aws-amplify';
import awsconfig from './aws-exports';
Amplify.configure(awsconfig);
API.configure(awsconfig);
I am using npm package: aws-amplify 3.3.21
I had this same issue and I managed to resolve it by configuring the exports on the "Api" object directly:
API.configure(aws_exports);
Previously it worked for me with just setting it on Amplify.configure, but it seems a newer version of Amplify requires it on the sub module itself.
Some more bits and pieces can be found here in this long-standing issue (in which the same issue popped up for Auth, but I applied the same to both in my case and it fixed it): https://github.com/aws-amplify/amplify-js/issues/4315
You need to call API.configure() after Amplify.configure is called, or else your API setup won't be applied, hence it returns API PetStore does not exist
import Amplify, { API } from 'aws-amplify'; // this part depends on which Amplify you are using. but make sure to import API
Amplify.configure({
Auth: {
...
},
API: {
endpoints: [
{
name: "PetStore", // name of the API in API Gateway console
endpoint: "https://XXX.execute-api.eu-central-1.amazonaws.com/dev",
region: "eu-central-1",
paths: ['/']
}
]
}
});
// Call this
API.configure(); // no awsconfig required as you have set your own
We changed the version of aws-amplify from 3 back to a previous version "aws-amplify": "^2.2.2" in package.json and that resolved it.
Think version 3 broke the manual configuration of aws-amplify.
Try changing the version to a previous version you know worked.
API * does not exist usually means you haven't pushed the REST API you created. If you can't use amplify push have you manually created and amplify API through the console?
Related
I'm trying to deploy my Svelte app on AWS Amplify, I push the commits, Amplify builds and verifies the app, but then if I visit the app URL it's just a blank page, it might be an adapter problem? I tried the node.js and static ones but no luck
If you want to deploy a Sveltekit application to AWS Amplify. You need to use the #sveltejs/adapter-static, since it will serve your app via a static CDN.
Once you change the adapter, make sure to add a fallback in svelte.config.js:
// svelte.config.js
import adapter from '#sveltejs/adapter-static';
export default {
kit: {
adapter: adapter({
fallback: 'index.html'
})
}
};
In the end, this solved the problem:
svelte.config.js
import adapter from '#sveltejs/adapter-static';
/** #type {import('#sveltejs/kit').Config} */
const config = {
kit: {
adapter: adapter(),
prerender: {
default: true
}
}
};
export default config;
I need to configure the RN SDK for AWS timestream but I keep getting an error:
Cant find variable Credential.
import { TimestreamQueryClient, CreateDatabaseCommand } from "#aws-sdk/client-timestream-query";
const client = new TimestreamQueryClient({
region: "eu-west-1",
credentials: new Credential('XXXXXXXXXXXX', 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXX'), // fails here
apiVersion: 'latest'
});
What am I doing wrong here?!
I was not able to find any documentation regarding the SDK configuration in RN.
I see that you are using the AWS SDK for JavaScript v3. To successfully use this API, you need to setup you DEV environment - including your creds. All these details are discussed in the AWS JavaScript V3 DEV Guide. I recommend that you read topics in this guide - which includes setting up your creds.
Setting up the SDK for JavaScript
As you want to work in React - this topic is very important for you to read - it has all the required instructions:
Getting started in React Native
This Guide is also referenced from the doc you pointed me too:
I'm hosting Strapi CMS on Heroku which has a limited amount of space so need to store media independently of the app.
To do this I installed strapi-provider-upload-aws-s3 and followed all of the configuration steps provided in the documentation but media is still being added to the public/uploads folder instead of my AWS S3 bucket and I can’t work out why. I’ve configured plugins.js, middlewares.js and updated my bucket policy.
Does anyone know if I need to do anything else to get this working for Strapi version 4.1.2?
I've also tried everything on this thread but I think the solutions are for version 3 because they're not working for me.
Just got it working by creating a new Strapi project, and found out that the NPM instructions are incorrect. You need to wrap the provider and provider options in config: {}. You also have to use the package's long name 'strapi-provider-upload-aws-s3'
module.exports = ({ env }) => ({
// ...
upload: {
config: {
provider: 'strapi-provider-upload-aws-s3',
providerOptions: {
accessKeyId: 'id',
secretAccessKey: 'key',
region: 'eu-west-2',
params: {
Bucket: 'Bucket'
}
},
},
},
// ...
});``
I've got a Next.js application that uses AWS Cognito userpools for authentication. I have a custom UI and am using the aws-amplify package directly invoking signIn/signOut/etc... in my code. (I previously used the AWS Hosted UI and had the same problem set out below - I hoped switching and digging into the actual APIs who reveal my problem but it hasn't)
Everything in development (running on localhost) is working correctly - I'm able to login and get access to my current session both in a page's render function using
import { Auth } from 'aws-amplify';
...
export default const MyPage = (props) => {
useEffect(async () => {
const session = await Auth.currentSession();
...
}
...
}
and during SSR
import { withSSRContext } from 'aws-amplify';
...
export async function getServerSideProps(context) {
...
const SSR = withSSRContext(context);
const session = await SSR.Auth.currentSession();
...
}
However, when I deploy to AWS Amplify where I run my staging environment, the call to get the current session during SSR fails. This results in the page rendering as if the user is not logged in then switching when the client is able to determine that the user is in fact logged in.
Current Hypothesis - missing cookies(??):
I've checked that during the login process that the AWS cookies are being set correctly in the browser. I've also checked and devtools tells me the cookies are correctly being sent to the server with the request.
However, if I log out context.req.headers inside getServerSideProps in my staging environment, the cookie header is missing (whereas in my dev environment it appears correctly). If this is true, this would explain what I'm seeing as getServerSideProps isn't seeing my auth tokens, etc... but I can't see why the cookie headers would be stripped?
Has anyone seen anything like this before? Is this even possible? If so, why would this happen? I assume I'm missing something, e.g. config related, but I feel like I've followed the docs pretty closely - my current conf looks like this
Amplify.configure({
Auth: {...}
ssr: true
});
Next.js version is 11.1.2 (latest)
Any help very much appreciated!
You have to use Next#11.0.0 to use getServerSideProps, withSSRContext and Auth module in production.
I had same issue.
My solution was that disconnect a branch has an authentication problem once and reconnect the branch.
What are your build settings? I guess you are using next build && next export in which case this getServerSideProps shall not work. See https://nextjs.org/docs/advanced-features/static-html-export#unsupported-features
To use SSR with AWS amplify see https://docs.aws.amazon.com/amplify/latest/userguide/server-side-rendering-amplify.html#redeploy-ssg-to-ssr or consider deploying on a node server that is actually a server that you can start with next start like AWS EC2 or deploy on Vercel.
Otherwise if you use next export have to make do with client side data fetch only with client side updates only and cannot use dynamic server side features of nextjs.
One reason for context.req.headers not having any cookie in it is because CloudFront distribution is not forwarding any cookies.
This “CloudFront Behaviour” can be changed in two ways:
Forward all cookies, OR
Forward specified cookies (i.e. array of cookie names)
To change the behaviour, navigate to CloudFront on AWS console > Distributions > your_distribution > Behaviors Tab.
Then Edit existing or Create new behaviour > Change cookies settings (for example set it to "All")
I'm attempting to setup a custom authenticator with ember simple auth. I'm using Ember CLI and according to the Simple Auth ReadMe on GitHub it states. Note that when you're not using Ember CLI the authenticator will not be registered with the container automatically and you need to do that in an initializer.
It does not state where you need to put your authenticator (or authorizer for that matter) in your directory structure in order for it to be registered by Ember CLI automatically. After creating my file in app/authenticators/custom.js (as shown in the examples of the read me) I expected it to be registered with the container. Looking in Ember Inspector it's no where to be found.
Does anyone have any insight into this? Where are these files meant to be placed?
Please ask if any additional information is needed.
Ember: 1.7.0
Ember Data: 1.0.0-beta.10
Ember Simple Auth: 0.7.1
The latest version of Ember CLI should actually auto-register the authenticator - make sure you're using that (you probably aren't as you're still at Ember 1.7.0). That should solve it.
Make sure you have your initializer in /app/initializers/. Initializers in this directory are automatically set up by ember-cli.
// app/initializers/authentication.js
import CustomAuthenticator from '../authenticators/custom';
export default {
name: 'authentication',
before: 'simple-auth',
initialize: function(container, application) {
container.register('authenticator:custom', CustomAuthenticator);
}
};
I am getting the same issue and I have Ember 1.8.1
Error is:
Uncaught ReferenceError: CustomAuthenticator is not defined
in file app/authenticators/custom.js
I needed to add an initializer and change the code found in the docs to this below, and it works
import Base from 'simple-auth/authenticators/base';
var CustomAuthenticator = Base.extend({
restore: function(data) {
},
authenticate: function(options) {
},
invalidate: function(data) {
}
});
export default CustomAuthenticator;