How to get an AWS EC2 instance ID from within that EC2 instance?
2022-02-14
Question How can I find out the instance id of an ec2 instance from within the ec2 instance? Answer See the EC2 documentation on the subject. Run: wget -q -O - http://169.254.169.254/latest/meta-data/instance-id If you need programmatic access to the instance ID from within a script, die() { status=$1; shift; echo "FATAL: $*"; exit $status; } EC2_INSTANCE_ID="`wget -q -O - http://169.254.169.254/latest/meta-data/instance-id || die \"wget instance-id has failed: $?\"`" Here is an example of a more advanced use (retrieve instance ID as well as availability zone and region, etc.…
How to handle errors with boto3?
2022-02-14
Question I am trying to figure how to do proper error handling with boto3. I am trying to create an IAM user: def create_user(username, iam_conn): try: user = iam_conn.create_user(UserName=username) return user except Exception as e: return e When the call to create_user succeeds, I get a neat object that contains the http status code of the API call and the data of the newly created user. Example: {'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': 'omitted' }, u'User': {u'Arn': 'arn:aws:iam::omitted:user/omitted', u'CreateDate': datetime.…
How to load npm modules in AWS Lambda?
2022-02-14
Question I've created several Lambda functions using the web based editor. So far so good. I'd now like to start extending those with modules (such as Q for promises). I can't figure out how to get the modules out to Lambda so they can be consumed by my functions. I've read through Using Packages and Native nodejs Modules in AWS Lambda but it seems to involve setting up an EC2 and running Lambda functions from there.…
How to pass a querystring or route parameter to AWS Lambda from Amazon API Gateway
2022-02-14
Question for instance if we want to use GET /user?name=bob or GET /user/bob How would you pass both of these examples as a parameter to the Lambda function? I saw something about setting a "mapped from" in the documentation, but I can't find that setting in the API Gateway console. method.request.path.parameter-name for a path parameter named parameter-name as defined in the Method Request page. method.request.querystring.parameter-name for a query string parameter named parameter-name as defined in the Method Request page.…
How to rename files and folder in Amazon S3?
2022-02-14
Question Is there any function to rename files and folders in Amazon S3? Any related suggestions are also welcome. Answer I just tested this and it works: aws s3 --recursive mv s3://<bucketname>/<folder_name_from> s3://<bucket>/<folder_name_to>
How to safely upgrade an Amazon EC2 instance from t1.micro to large? [closed]
2022-02-14
Question Closed. This question is off-topic. It is not currently accepting answers. </div> Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 10 years ago. Improve this question I have an Amazon EC2 micro instance (t1.micro). I want to upgrade this instance to large. This is our production environment, so what is the safest way to do this? Is there any step by step guide to do this?…
How to test credentials for AWS Command Line Tools
2022-02-14
Question Is there a command/subcommand that can be passed to the aws utility that can 1) verify that the credentials in the ~/.aws/credentials file are valid, and 2) give some indication which user the credentials belong to? I'm looking for something generic that doesn't make any assumptions about the user having permissions to IAM or any specific service. The use case for this is a deploy-time sanity check to make sure that the credentials are good.…